1 // RUN: %clang_cc1 -Werror -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \ 2 // RUN: -triple i686--windows -Oz -emit-llvm %s -o - \ 3 // RUN: | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-I386 4 // RUN: %clang_cc1 -Werror -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \ 5 // RUN: -triple x86_64--windows -Oz -emit-llvm %s -o - \ 6 // RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X64 7 8 #include <intrin.h> 9 10 #if defined(__i386__) 11 char test__readfsbyte(unsigned long Offset) { 12 return __readfsbyte(++Offset); 13 } 14 // CHECK-I386-LABEL: define dso_local signext i8 @test__readfsbyte(i32 noundef %Offset) 15 // CHECK-I386: %inc = add i32 %Offset, 1 16 // CHECK-I386: [[PTR:%[0-9]+]] = inttoptr i32 %inc to ptr addrspace(257) 17 // CHECK-I386: [[VALUE:%[0-9]+]] = load volatile i8, ptr addrspace(257) [[PTR]], align 1 18 // CHECK-I386: ret i8 [[VALUE:%[0-9]+]] 19 20 short test__readfsword(unsigned long Offset) { 21 return __readfsword(++Offset); 22 } 23 // CHECK-I386-LABEL: define dso_local signext i16 @test__readfsword(i32 noundef %Offset) 24 // CHECK-I386: %inc = add i32 %Offset, 1 25 // CHECK-I386: [[PTR:%[0-9]+]] = inttoptr i32 %inc to ptr addrspace(257) 26 // CHECK-I386: [[VALUE:%[0-9]+]] = load volatile i16, ptr addrspace(257) [[PTR]], align 2 27 // CHECK-I386: ret i16 [[VALUE:%[0-9]+]] 28 29 long test__readfsdword(unsigned long Offset) { 30 return __readfsdword(++Offset); 31 } 32 // CHECK-I386-LABEL: define dso_local i32 @test__readfsdword(i32 noundef %Offset) 33 // CHECK-I386: %inc = add i32 %Offset, 1 34 // CHECK-I386: [[PTR:%[0-9]+]] = inttoptr i32 %inc to ptr addrspace(257) 35 // CHECK-I386: [[VALUE:%[0-9]+]] = load volatile i32, ptr addrspace(257) [[PTR]], align 4 36 // CHECK-I386: ret i32 [[VALUE:%[0-9]+]] 37 38 long long test__readfsqword(unsigned long Offset) { 39 return __readfsqword(++Offset); 40 } 41 // CHECK-I386-LABEL: define dso_local i64 @test__readfsqword(i32 noundef %Offset) 42 // CHECK-I386: %inc = add i32 %Offset, 1 43 // CHECK-I386: [[PTR:%[0-9]+]] = inttoptr i32 %inc to ptr addrspace(257) 44 // CHECK-I386: [[VALUE:%[0-9]+]] = load volatile i64, ptr addrspace(257) [[PTR]], align 8 45 // CHECK-I386: ret i64 [[VALUE:%[0-9]+]] 46 #endif 47 48 __int64 test__emul(int a, int b) { 49 return __emul(a, b); 50 } 51 // CHECK-LABEL: define dso_local range(i64 -4611686016279904256, 4611686018427387905) i64 @test__emul(i32 noundef %a, i32 noundef %b) 52 // CHECK: [[X:%[0-9]+]] = sext i32 %a to i64 53 // CHECK: [[Y:%[0-9]+]] = sext i32 %b to i64 54 // CHECK: [[RES:%[0-9]+]] = mul nsw i64 [[Y]], [[X]] 55 // CHECK: ret i64 [[RES]] 56 57 unsigned __int64 test__emulu(unsigned int a, unsigned int b) { 58 return __emulu(a, b); 59 } 60 // CHECK-LABEL: define dso_local range(i64 0, -8589934590) i64 @test__emulu(i32 noundef %a, i32 noundef %b) 61 // CHECK: [[X:%[0-9]+]] = zext i32 %a to i64 62 // CHECK: [[Y:%[0-9]+]] = zext i32 %b to i64 63 // CHECK: [[RES:%[0-9]+]] = mul nuw i64 [[Y]], [[X]] 64 // CHECK: ret i64 [[RES]] 65 66 67 unsigned char test_inbyte(unsigned short port) { 68 return __inbyte(port); 69 } 70 // CHECK-LABEL: i8 @test_inbyte(i16 noundef 71 // CHECK-SAME: [[PORT:%.*]]) 72 // CHECK: [[TMP0:%.*]] = tail call i8 asm sideeffect "inb ${1:w}, ${0:b}", "={ax},N{dx},~{dirflag},~{fpsr},~{flags}"(i16 [[PORT]]) 73 // CHECK-NEXT: ret i8 [[TMP0]] 74 75 unsigned short test_inword(unsigned short port) { 76 return __inword(port); 77 } 78 // CHECK-LABEL: i16 @test_inword(i16 noundef 79 // CHECK-SAME: [[PORT:%.*]]) 80 // CHECK: [[TMP0:%.*]] = tail call i16 asm sideeffect "inw ${1:w}, ${0:w}", "={ax},N{dx},~{dirflag},~{fpsr},~{flags}"(i16 [[PORT]]) 81 // CHECK-NEXT: ret i16 [[TMP0]] 82 83 unsigned long test_indword(unsigned short port) { 84 return __indword(port); 85 } 86 // CHECK-LABEL: i32 @test_indword(i16 noundef 87 // CHECK-SAME: [[PORT:%.*]]) 88 // CHECK: [[TMP0:%.*]] = tail call i32 asm sideeffect "inl ${1:w}, ${0:k}", "={ax},N{dx},~{dirflag},~{fpsr},~{flags}"(i16 [[PORT]]) 89 // CHECK-NEXT: ret i32 [[TMP0]] 90 91 void test_outbyte(unsigned short port, unsigned char data) { 92 return __outbyte(port, data); 93 } 94 // CHECK-LABEL: void @test_outbyte( 95 // CHECK-SAME: [[PORT:%.*]], 96 // CHECK-SAME: [[DATA:%.*]]) 97 // CHECK: tail call void asm sideeffect "outb ${0:b}, ${1:w}", "{ax},N{dx},~{dirflag},~{fpsr},~{flags}"(i8 [[DATA]], i16 [[PORT]]) 98 99 void test_outword(unsigned short port, unsigned short data) { 100 return __outword(port, data); 101 } 102 // CHECK-LABEL: void @test_outword( 103 // CHECK-SAME: [[PORT:%.*]], 104 // CHECK-SAME: [[DATA:%.*]]) 105 // CHECK: tail call void asm sideeffect "outw ${0:w}, ${1:w}", "{ax},N{dx},~{dirflag},~{fpsr},~{flags}"(i16 [[DATA]], i16 [[PORT]]) 106 107 void test_outdword(unsigned short port, unsigned long data) { 108 return __outdword(port, data); 109 } 110 // CHECK-LABEL: void @test_outdword( 111 // CHECK-SAME: [[PORT:%.*]], 112 // CHECK-SAME: [[DATA:%.*]]) 113 // CHECK: tail call void asm sideeffect "outl ${0:k}, ${1:w}", "{ax},N{dx},~{dirflag},~{fpsr},~{flags}"(i32 [[DATA]], i16 [[PORT]]) 114 115 #if defined(__x86_64__) 116 117 char test__readgsbyte(unsigned long Offset) { 118 return __readgsbyte(++Offset); 119 } 120 // CHECK-X64-LABEL: define dso_local i8 @test__readgsbyte(i32 noundef %Offset) 121 // CHECK-X64: %inc = add i32 %Offset, 1 122 // CHECK-X64: [[ZEXT:%[0-9]+]] = zext i32 %inc to i64 123 // CHECK-X64: [[PTR:%[0-9]+]] = inttoptr i64 [[ZEXT]] to ptr addrspace(256) 124 // CHECK-X64: [[VALUE:%[0-9]+]] = load volatile i8, ptr addrspace(256) [[PTR]], align 1 125 // CHECK-X64: ret i8 [[VALUE:%[0-9]+]] 126 127 short test__readgsword(unsigned long Offset) { 128 return __readgsword(++Offset); 129 } 130 // CHECK-X64-LABEL: define dso_local i16 @test__readgsword(i32 noundef %Offset) 131 // CHECK-X64: %inc = add i32 %Offset, 1 132 // CHECK-X64: [[ZEXT:%[0-9]+]] = zext i32 %inc to i64 133 // CHECK-X64: [[PTR:%[0-9]+]] = inttoptr i64 [[ZEXT]] to ptr addrspace(256) 134 // CHECK-X64: [[VALUE:%[0-9]+]] = load volatile i16, ptr addrspace(256) [[PTR]], align 2 135 // CHECK-X64: ret i16 [[VALUE:%[0-9]+]] 136 137 long test__readgsdword(unsigned long Offset) { 138 return __readgsdword(++Offset); 139 } 140 // CHECK-X64-LABEL: define dso_local i32 @test__readgsdword(i32 noundef %Offset) 141 // CHECK-X64: %inc = add i32 %Offset, 1 142 // CHECK-X64: [[ZEXT:%[0-9]+]] = zext i32 %inc to i64 143 // CHECK-X64: [[PTR:%[0-9]+]] = inttoptr i64 [[ZEXT]] to ptr addrspace(256) 144 // CHECK-X64: [[VALUE:%[0-9]+]] = load volatile i32, ptr addrspace(256) [[PTR]], align 4 145 // CHECK-X64: ret i32 [[VALUE:%[0-9]+]] 146 147 long long test__readgsqword(unsigned long Offset) { 148 return __readgsqword(++Offset); 149 } 150 // CHECK-X64-LABEL: define dso_local i64 @test__readgsqword(i32 noundef %Offset) 151 // CHECK-X64: %inc = add i32 %Offset, 1 152 // CHECK-X64: [[ZEXT:%[0-9]+]] = zext i32 %inc to i64 153 // CHECK-X64: [[PTR:%[0-9]+]] = inttoptr i64 [[ZEXT]] to ptr addrspace(256) 154 // CHECK-X64: [[VALUE:%[0-9]+]] = load volatile i64, ptr addrspace(256) [[PTR]], align 8 155 // CHECK-X64: ret i64 [[VALUE:%[0-9]+]] 156 157 __int64 test__mulh(__int64 a, __int64 b) { 158 return __mulh(a, b); 159 } 160 // CHECK-X64-LABEL: define dso_local range(i64 -4611686018427387904, 4611686018427387905) i64 @test__mulh(i64 noundef %a, i64 noundef %b) 161 // CHECK-X64: = mul nsw i128 % 162 163 unsigned __int64 test__umulh(unsigned __int64 a, unsigned __int64 b) { 164 return __umulh(a, b); 165 } 166 // CHECK-X64-LABEL: define dso_local range(i64 0, -1) i64 @test__umulh(i64 noundef %a, i64 noundef %b) 167 // CHECK-X64: = mul nuw i128 % 168 169 __int64 test_mul128(__int64 Multiplier, 170 __int64 Multiplicand, 171 __int64 *HighProduct) { 172 return _mul128(Multiplier, Multiplicand, HighProduct); 173 } 174 // CHECK-X64-LABEL: define dso_local i64 @test_mul128(i64 noundef %Multiplier, i64 noundef %Multiplicand, ptr{{.*}} initializes((0, 8)) %HighProduct) 175 // CHECK-X64: = sext i64 %Multiplier to i128 176 // CHECK-X64: = sext i64 %Multiplicand to i128 177 // CHECK-X64: = mul nsw i128 % 178 // CHECK-X64: store i64 % 179 // CHECK-X64: ret i64 % 180 181 unsigned __int64 test_umul128(unsigned __int64 Multiplier, 182 unsigned __int64 Multiplicand, 183 unsigned __int64 *HighProduct) { 184 return _umul128(Multiplier, Multiplicand, HighProduct); 185 } 186 // CHECK-X64-LABEL: define dso_local i64 @test_umul128(i64 noundef %Multiplier, i64 noundef %Multiplicand, ptr{{.*}} initializes((0, 8)) %HighProduct) 187 // CHECK-X64: = zext i64 %Multiplier to i128 188 // CHECK-X64: = zext i64 %Multiplicand to i128 189 // CHECK-X64: = mul nuw i128 % 190 // CHECK-X64: store i64 % 191 // CHECK-X64: ret i64 % 192 193 unsigned __int64 test__shiftleft128(unsigned __int64 l, unsigned __int64 h, 194 unsigned char d) { 195 return __shiftleft128(l, h, d); 196 } 197 // CHECK-X64-LABEL: define dso_local noundef i64 @test__shiftleft128(i64 noundef %l, i64 noundef %h, i8 noundef %d) 198 // CHECK-X64: = zext i8 %{{.*}} to i64 199 // CHECK-X64: = tail call i64 @llvm.fshl.i64(i64 %h, i64 %l, i64 %{{.*}}) 200 // CHECK-X64: ret i64 % 201 202 unsigned __int64 test__shiftright128(unsigned __int64 l, unsigned __int64 h, 203 unsigned char d) { 204 return __shiftright128(l, h, d); 205 } 206 // CHECK-X64-LABEL: define dso_local noundef i64 @test__shiftright128(i64 noundef %l, i64 noundef %h, i8 noundef %d) 207 // CHECK-X64: = zext i8 %{{.*}} to i64 208 // CHECK-X64: = tail call i64 @llvm.fshr.i64(i64 %h, i64 %l, i64 %{{.*}}) 209 // CHECK-X64: ret i64 % 210 211 #endif // defined(__x86_64__) 212