Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / X86 / ms-x86-intrinsics.c
blobb4b8f5dc0b8c55539afa76d803236f1a2182cdea
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
8 #include <intrin.h>
10 #if defined(__i386__)
11 char test__readfsbyte(unsigned long Offset) {
12 return __readfsbyte(++Offset);
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]+]]
20 short test__readfsword(unsigned long Offset) {
21 return __readfsword(++Offset);
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]+]]
29 long test__readfsdword(unsigned long Offset) {
30 return __readfsdword(++Offset);
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]+]]
38 long long test__readfsqword(unsigned long Offset) {
39 return __readfsqword(++Offset);
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
48 __int64 test__emul(int a, int b) {
49 return __emul(a, b);
51 // CHECK-LABEL: define dso_local 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]]
57 unsigned __int64 test__emulu(unsigned int a, unsigned int b) {
58 return __emulu(a, b);
60 // CHECK-LABEL: define dso_local 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]]
66 #if defined(__x86_64__)
68 char test__readgsbyte(unsigned long Offset) {
69 return __readgsbyte(++Offset);
71 // CHECK-X64-LABEL: define dso_local i8 @test__readgsbyte(i32 noundef %Offset)
72 // CHECK-X64: %inc = add i32 %Offset, 1
73 // CHECK-X64: [[ZEXT:%[0-9]+]] = zext i32 %inc to i64
74 // CHECK-X64: [[PTR:%[0-9]+]] = inttoptr i64 [[ZEXT]] to ptr addrspace(256)
75 // CHECK-X64: [[VALUE:%[0-9]+]] = load volatile i8, ptr addrspace(256) [[PTR]], align 1
76 // CHECK-X64: ret i8 [[VALUE:%[0-9]+]]
78 short test__readgsword(unsigned long Offset) {
79 return __readgsword(++Offset);
81 // CHECK-X64-LABEL: define dso_local i16 @test__readgsword(i32 noundef %Offset)
82 // CHECK-X64: %inc = add i32 %Offset, 1
83 // CHECK-X64: [[ZEXT:%[0-9]+]] = zext i32 %inc to i64
84 // CHECK-X64: [[PTR:%[0-9]+]] = inttoptr i64 [[ZEXT]] to ptr addrspace(256)
85 // CHECK-X64: [[VALUE:%[0-9]+]] = load volatile i16, ptr addrspace(256) [[PTR]], align 2
86 // CHECK-X64: ret i16 [[VALUE:%[0-9]+]]
88 long test__readgsdword(unsigned long Offset) {
89 return __readgsdword(++Offset);
91 // CHECK-X64-LABEL: define dso_local i32 @test__readgsdword(i32 noundef %Offset)
92 // CHECK-X64: %inc = add i32 %Offset, 1
93 // CHECK-X64: [[ZEXT:%[0-9]+]] = zext i32 %inc to i64
94 // CHECK-X64: [[PTR:%[0-9]+]] = inttoptr i64 [[ZEXT]] to ptr addrspace(256)
95 // CHECK-X64: [[VALUE:%[0-9]+]] = load volatile i32, ptr addrspace(256) [[PTR]], align 4
96 // CHECK-X64: ret i32 [[VALUE:%[0-9]+]]
98 long long test__readgsqword(unsigned long Offset) {
99 return __readgsqword(++Offset);
101 // CHECK-X64-LABEL: define dso_local i64 @test__readgsqword(i32 noundef %Offset)
102 // CHECK-X64: %inc = add i32 %Offset, 1
103 // CHECK-X64: [[ZEXT:%[0-9]+]] = zext i32 %inc to i64
104 // CHECK-X64: [[PTR:%[0-9]+]] = inttoptr i64 [[ZEXT]] to ptr addrspace(256)
105 // CHECK-X64: [[VALUE:%[0-9]+]] = load volatile i64, ptr addrspace(256) [[PTR]], align 8
106 // CHECK-X64: ret i64 [[VALUE:%[0-9]+]]
108 __int64 test__mulh(__int64 a, __int64 b) {
109 return __mulh(a, b);
111 // CHECK-X64-LABEL: define dso_local i64 @test__mulh(i64 noundef %a, i64 noundef %b)
112 // CHECK-X64: = mul nsw i128 %
114 unsigned __int64 test__umulh(unsigned __int64 a, unsigned __int64 b) {
115 return __umulh(a, b);
117 // CHECK-X64-LABEL: define dso_local i64 @test__umulh(i64 noundef %a, i64 noundef %b)
118 // CHECK-X64: = mul nuw i128 %
120 __int64 test_mul128(__int64 Multiplier,
121 __int64 Multiplicand,
122 __int64 *HighProduct) {
123 return _mul128(Multiplier, Multiplicand, HighProduct);
125 // CHECK-X64-LABEL: define dso_local i64 @test_mul128(i64 noundef %Multiplier, i64 noundef %Multiplicand, ptr{{[a-z_ ]*}}%HighProduct)
126 // CHECK-X64: = sext i64 %Multiplier to i128
127 // CHECK-X64: = sext i64 %Multiplicand to i128
128 // CHECK-X64: = mul nsw i128 %
129 // CHECK-X64: store i64 %
130 // CHECK-X64: ret i64 %
132 unsigned __int64 test_umul128(unsigned __int64 Multiplier,
133 unsigned __int64 Multiplicand,
134 unsigned __int64 *HighProduct) {
135 return _umul128(Multiplier, Multiplicand, HighProduct);
137 // CHECK-X64-LABEL: define dso_local i64 @test_umul128(i64 noundef %Multiplier, i64 noundef %Multiplicand, ptr{{[a-z_ ]*}}%HighProduct)
138 // CHECK-X64: = zext i64 %Multiplier to i128
139 // CHECK-X64: = zext i64 %Multiplicand to i128
140 // CHECK-X64: = mul nuw i128 %
141 // CHECK-X64: store i64 %
142 // CHECK-X64: ret i64 %
144 unsigned __int64 test__shiftleft128(unsigned __int64 l, unsigned __int64 h,
145 unsigned char d) {
146 return __shiftleft128(l, h, d);
148 // CHECK-X64-LABEL: define dso_local i64 @test__shiftleft128(i64 noundef %l, i64 noundef %h, i8 noundef %d)
149 // CHECK-X64: = zext i8 %{{.*}} to i64
150 // CHECK-X64: = tail call i64 @llvm.fshl.i64(i64 %h, i64 %l, i64 %{{.*}})
151 // CHECK-X64: ret i64 %
153 unsigned __int64 test__shiftright128(unsigned __int64 l, unsigned __int64 h,
154 unsigned char d) {
155 return __shiftright128(l, h, d);
157 // CHECK-X64-LABEL: define dso_local i64 @test__shiftright128(i64 noundef %l, i64 noundef %h, i8 noundef %d)
158 // CHECK-X64: = zext i8 %{{.*}} to i64
159 // CHECK-X64: = tail call i64 @llvm.fshr.i64(i64 %h, i64 %l, i64 %{{.*}})
160 // CHECK-X64: ret i64 %
162 #endif // defined(__x86_64__)