1 // RUN: %clang_cc1 -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 -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 #if defined(__i386__)
test__readfsbyte(unsigned long Offset)9 char test__readfsbyte(unsigned long Offset) {
10 return __readfsbyte(++Offset);
11 }
12 // CHECK-I386-LABEL: define dso_local signext i8 @test__readfsbyte(i32 %Offset)
13 // CHECK-I386: %inc = add i32 %Offset, 1
14 // CHECK-I386: [[PTR:%[0-9]+]] = inttoptr i32 %inc to i8 addrspace(257)*
15 // CHECK-I386: [[VALUE:%[0-9]+]] = load volatile i8, i8 addrspace(257)* [[PTR]], align 1
16 // CHECK-I386: ret i8 [[VALUE:%[0-9]+]]
17
test__readfsword(unsigned long Offset)18 short test__readfsword(unsigned long Offset) {
19 return __readfsword(++Offset);
20 }
21 // CHECK-I386-LABEL: define dso_local signext i16 @test__readfsword(i32 %Offset)
22 // CHECK-I386: %inc = add i32 %Offset, 1
23 // CHECK-I386: [[PTR:%[0-9]+]] = inttoptr i32 %inc to i16 addrspace(257)*
24 // CHECK-I386: [[VALUE:%[0-9]+]] = load volatile i16, i16 addrspace(257)* [[PTR]], align 2
25 // CHECK-I386: ret i16 [[VALUE:%[0-9]+]]
26
test__readfsdword(unsigned long Offset)27 long test__readfsdword(unsigned long Offset) {
28 return __readfsdword(++Offset);
29 }
30 // CHECK-I386-LABEL: define dso_local i32 @test__readfsdword(i32 %Offset)
31 // CHECK-I386: %inc = add i32 %Offset, 1
32 // CHECK-I386: [[PTR:%[0-9]+]] = inttoptr i32 %inc to i32 addrspace(257)*
33 // CHECK-I386: [[VALUE:%[0-9]+]] = load volatile i32, i32 addrspace(257)* [[PTR]], align 4
34 // CHECK-I386: ret i32 [[VALUE:%[0-9]+]]
35
test__readfsqword(unsigned long Offset)36 long long test__readfsqword(unsigned long Offset) {
37 return __readfsqword(++Offset);
38 }
39 // CHECK-I386-LABEL: define dso_local i64 @test__readfsqword(i32 %Offset)
40 // CHECK-I386: %inc = add i32 %Offset, 1
41 // CHECK-I386: [[PTR:%[0-9]+]] = inttoptr i32 %inc to i64 addrspace(257)*
42 // CHECK-I386: [[VALUE:%[0-9]+]] = load volatile i64, i64 addrspace(257)* [[PTR]], align 8
43 // CHECK-I386: ret i64 [[VALUE:%[0-9]+]]
44 #endif
45
test__emul(int a,int b)46 __int64 test__emul(int a, int b) {
47 return __emul(a, b);
48 }
49 // CHECK-LABEL: define dso_local i64 @test__emul(i32 %a, i32 %b)
50 // CHECK: [[X:%[0-9]+]] = sext i32 %a to i64
51 // CHECK: [[Y:%[0-9]+]] = sext i32 %b to i64
52 // CHECK: [[RES:%[0-9]+]] = mul nsw i64 [[Y]], [[X]]
53 // CHECK: ret i64 [[RES]]
54
test__emulu(unsigned int a,unsigned int b)55 unsigned __int64 test__emulu(unsigned int a, unsigned int b) {
56 return __emulu(a, b);
57 }
58 // CHECK-LABEL: define dso_local i64 @test__emulu(i32 %a, i32 %b)
59 // CHECK: [[X:%[0-9]+]] = zext i32 %a to i64
60 // CHECK: [[Y:%[0-9]+]] = zext i32 %b to i64
61 // CHECK: [[RES:%[0-9]+]] = mul nuw i64 [[Y]], [[X]]
62 // CHECK: ret i64 [[RES]]
63
64 #if defined(__x86_64__)
65
test__readgsbyte(unsigned long Offset)66 char test__readgsbyte(unsigned long Offset) {
67 return __readgsbyte(++Offset);
68 }
69 // CHECK-X64-LABEL: define dso_local i8 @test__readgsbyte(i32 %Offset)
70 // CHECK-X64: %inc = add i32 %Offset, 1
71 // CHECK-X64: [[ZEXT:%[0-9]+]] = zext i32 %inc to i64
72 // CHECK-X64: [[PTR:%[0-9]+]] = inttoptr i64 [[ZEXT]] to i8 addrspace(256)*
73 // CHECK-X64: [[VALUE:%[0-9]+]] = load volatile i8, i8 addrspace(256)* [[PTR]], align 1
74 // CHECK-X64: ret i8 [[VALUE:%[0-9]+]]
75
test__readgsword(unsigned long Offset)76 short test__readgsword(unsigned long Offset) {
77 return __readgsword(++Offset);
78 }
79 // CHECK-X64-LABEL: define dso_local i16 @test__readgsword(i32 %Offset)
80 // CHECK-X64: %inc = add i32 %Offset, 1
81 // CHECK-X64: [[ZEXT:%[0-9]+]] = zext i32 %inc to i64
82 // CHECK-X64: [[PTR:%[0-9]+]] = inttoptr i64 [[ZEXT]] to i16 addrspace(256)*
83 // CHECK-X64: [[VALUE:%[0-9]+]] = load volatile i16, i16 addrspace(256)* [[PTR]], align 2
84 // CHECK-X64: ret i16 [[VALUE:%[0-9]+]]
85
test__readgsdword(unsigned long Offset)86 long test__readgsdword(unsigned long Offset) {
87 return __readgsdword(++Offset);
88 }
89 // CHECK-X64-LABEL: define dso_local i32 @test__readgsdword(i32 %Offset)
90 // CHECK-X64: %inc = add i32 %Offset, 1
91 // CHECK-X64: [[ZEXT:%[0-9]+]] = zext i32 %inc to i64
92 // CHECK-X64: [[PTR:%[0-9]+]] = inttoptr i64 [[ZEXT]] to i32 addrspace(256)*
93 // CHECK-X64: [[VALUE:%[0-9]+]] = load volatile i32, i32 addrspace(256)* [[PTR]], align 4
94 // CHECK-X64: ret i32 [[VALUE:%[0-9]+]]
95
test__readgsqword(unsigned long Offset)96 long long test__readgsqword(unsigned long Offset) {
97 return __readgsqword(++Offset);
98 }
99 // CHECK-X64-LABEL: define dso_local i64 @test__readgsqword(i32 %Offset)
100 // CHECK-X64: %inc = add i32 %Offset, 1
101 // CHECK-X64: [[ZEXT:%[0-9]+]] = zext i32 %inc to i64
102 // CHECK-X64: [[PTR:%[0-9]+]] = inttoptr i64 [[ZEXT]] to i64 addrspace(256)*
103 // CHECK-X64: [[VALUE:%[0-9]+]] = load volatile i64, i64 addrspace(256)* [[PTR]], align 8
104 // CHECK-X64: ret i64 [[VALUE:%[0-9]+]]
105
test__mulh(__int64 a,__int64 b)106 __int64 test__mulh(__int64 a, __int64 b) {
107 return __mulh(a, b);
108 }
109 // CHECK-X64-LABEL: define dso_local i64 @test__mulh(i64 %a, i64 %b)
110 // CHECK-X64: = mul nsw i128 %
111
test__umulh(unsigned __int64 a,unsigned __int64 b)112 unsigned __int64 test__umulh(unsigned __int64 a, unsigned __int64 b) {
113 return __umulh(a, b);
114 }
115 // CHECK-X64-LABEL: define dso_local i64 @test__umulh(i64 %a, i64 %b)
116 // CHECK-X64: = mul nuw i128 %
117
test_mul128(__int64 Multiplier,__int64 Multiplicand,__int64 * HighProduct)118 __int64 test_mul128(__int64 Multiplier,
119 __int64 Multiplicand,
120 __int64 *HighProduct) {
121 return _mul128(Multiplier, Multiplicand, HighProduct);
122 }
123 // CHECK-X64-LABEL: define dso_local i64 @test_mul128(i64 %Multiplier, i64 %Multiplicand, i64*{{[a-z_ ]*}}%HighProduct)
124 // CHECK-X64: = sext i64 %Multiplier to i128
125 // CHECK-X64: = sext i64 %Multiplicand to i128
126 // CHECK-X64: = mul nsw i128 %
127 // CHECK-X64: store i64 %
128 // CHECK-X64: ret i64 %
129
test_umul128(unsigned __int64 Multiplier,unsigned __int64 Multiplicand,unsigned __int64 * HighProduct)130 unsigned __int64 test_umul128(unsigned __int64 Multiplier,
131 unsigned __int64 Multiplicand,
132 unsigned __int64 *HighProduct) {
133 return _umul128(Multiplier, Multiplicand, HighProduct);
134 }
135 // CHECK-X64-LABEL: define dso_local i64 @test_umul128(i64 %Multiplier, i64 %Multiplicand, i64*{{[a-z_ ]*}}%HighProduct)
136 // CHECK-X64: = zext i64 %Multiplier to i128
137 // CHECK-X64: = zext i64 %Multiplicand to i128
138 // CHECK-X64: = mul nuw i128 %
139 // CHECK-X64: store i64 %
140 // CHECK-X64: ret i64 %
141
test__shiftleft128(unsigned __int64 l,unsigned __int64 h,unsigned char d)142 unsigned __int64 test__shiftleft128(unsigned __int64 l, unsigned __int64 h,
143 unsigned char d) {
144 return __shiftleft128(l, h, d);
145 }
146 // CHECK-X64-LABEL: define dso_local i64 @test__shiftleft128(i64 %l, i64 %h, i8 %d)
147 // CHECK-X64: = zext i8 %{{.*}} to i64
148 // CHECK-X64: = tail call i64 @llvm.fshl.i64(i64 %h, i64 %l, i64 %{{.*}})
149 // CHECK-X64: ret i64 %
150
test__shiftright128(unsigned __int64 l,unsigned __int64 h,unsigned char d)151 unsigned __int64 test__shiftright128(unsigned __int64 l, unsigned __int64 h,
152 unsigned char d) {
153 return __shiftright128(l, h, d);
154 }
155 // CHECK-X64-LABEL: define dso_local i64 @test__shiftright128(i64 %l, i64 %h, i8 %d)
156 // CHECK-X64: = zext i8 %{{.*}} to i64
157 // CHECK-X64: = tail call i64 @llvm.fshr.i64(i64 %h, i64 %l, i64 %{{.*}})
158 // CHECK-X64: ret i64 %
159
160 #endif // defined(__x86_64__)
161