Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / asm.c
blob10102cc2c4db10e09e2bddba9076badd450701bd
1 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s
3 // PR10415
4 __asm__ ("foo1");
5 __asm__ ("foo2");
6 __asm__ ("foo3");
7 // CHECK: module asm "foo1"
8 // CHECK-NEXT: module asm "foo2"
9 // CHECK-NEXT: module asm "foo3"
11 void t1(int len) {
12 __asm__ volatile("" : "=&r"(len), "+&r"(len));
15 void t2(unsigned long long t) {
16 __asm__ volatile("" : "+m"(t));
19 void t3(unsigned char *src, unsigned long long temp) {
20 __asm__ volatile("" : "+m"(temp), "+r"(src));
23 void t4(void) {
24 unsigned long long a;
25 struct reg { unsigned long long a, b; } b;
27 __asm__ volatile ("":: "m"(a), "m"(b));
30 // PR3417
31 void t5(int i) {
32 asm("nop" : "=r"(i) : "0"(t5));
35 // PR3641
36 void t6(void) {
37 __asm__ volatile("" : : "i" (t6));
40 void t7(int a) {
41 __asm__ volatile("T7 NAMED: %[input]" : "+r"(a): [input] "i" (4));
42 // CHECK: @t7(i32
43 // CHECK: T7 NAMED: $1
46 void t8(void) {
47 __asm__ volatile("T8 NAMED MODIFIER: %c[input]" :: [input] "i" (4));
48 // CHECK: @t8()
49 // CHECK: T8 NAMED MODIFIER: ${0:c}
52 // PR3682
53 unsigned t9(unsigned int a) {
54 asm("bswap %0 %1" : "+r" (a));
55 return a;
58 // PR3908
59 void t10(int r) {
60 __asm__("PR3908 %[lf] %[xx] %[li] %[r]" : [r] "+r" (r) : [lf] "mx" (0), [li] "mr" (0), [xx] "x" ((double)(0)));
62 // CHECK: @t10(
63 // CHECK:PR3908 $1 $3 $2 $0
66 // PR3373
67 unsigned t11(signed char input) {
68 unsigned output;
69 __asm__("xyz"
70 : "=a" (output)
71 : "0" (input));
72 return output;
75 // PR3373
76 unsigned char t12(unsigned input) {
77 unsigned char output;
78 __asm__("xyz"
79 : "=a" (output)
80 : "0" (input));
81 return output;
84 unsigned char t13(unsigned input) {
85 unsigned char output;
86 __asm__("xyz %1"
87 : "=a" (output)
88 : "0" (input));
89 return output;
92 struct large {
93 int x[1000];
96 unsigned long t15(int x, struct large *P) {
97 __asm__("xyz "
98 : "=r" (x)
99 : "m" (*P), "0" (x));
100 return x;
103 // bitfield destination of an asm.
104 struct S {
105 int a : 4;
108 void t14(struct S *P) {
109 __asm__("abc %0" : "=r"(P->a) );
112 // PR4938
113 int t16(void) {
114 int a,b;
115 asm ( "nop;"
116 :"=%c" (a)
117 : "r" (b)
119 return 0;
122 // PR6475
123 void t17(void) {
124 int i;
125 __asm__ ( "nop": "=m"(i));
127 // CHECK: @t17()
128 // CHECK: call void asm "nop", "=*m,
131 int t18(unsigned data) {
132 int a, b;
134 asm("xyz" :"=a"(a), "=d"(b) : "a"(data));
135 return a + b;
136 // CHECK: t18(i32
137 // CHECK: = call {{.*}}asm "xyz"
138 // CHECK-NEXT: extractvalue
139 // CHECK-NEXT: extractvalue
142 // PR6780
143 int t19(unsigned data) {
144 int a, b;
146 asm("x{abc|def|ghi}z" :"=r"(a): "r"(data));
147 return a + b;
148 // CHECK: t19(i32
149 // CHECK: = call {{.*}}asm "x$(abc$|def$|ghi$)z"
152 // PR6845 - Mismatching source/dest fp types.
153 double t20(double x) {
154 register long double result;
155 __asm __volatile ("frndint" : "=t" (result) : "0" (x));
156 return result;
158 // CHECK: @t20
159 // CHECK: fpext double {{.*}} to x86_fp80
160 // CHECK-NEXT: call x86_fp80 asm sideeffect "frndint"
161 // CHECK: fptrunc x86_fp80 {{.*}} to double
164 float t21(long double x) {
165 register float result;
166 __asm __volatile ("frndint" : "=t" (result) : "0" (x));
167 return result;
168 // CHECK: @t21
169 // CHECK: call x86_fp80 asm sideeffect "frndint"
170 // CHECK-NEXT: fptrunc x86_fp80 {{.*}} to float
173 // accept 'l' constraint
174 unsigned char t22(unsigned char a, unsigned char b) {
175 unsigned int la = a;
176 unsigned int lb = b;
177 unsigned int bigres;
178 unsigned char res;
179 __asm__ ("0:\n1:\n" : [bigres] "=la"(bigres) : [la] "0"(la), [lb] "c"(lb) :
180 "edx", "cc");
181 res = bigres;
182 return res;
185 // accept 'l' constraint
186 unsigned char t23(unsigned char a, unsigned char b) {
187 unsigned int la = a;
188 unsigned int lb = b;
189 unsigned char res;
190 __asm__ ("0:\n1:\n" : [res] "=la"(res) : [la] "0"(la), [lb] "c"(lb) :
191 "edx", "cc");
192 return res;
195 void *t24(char c) {
196 void *addr;
197 // CHECK: @t24
198 // CHECK: zext i8 {{.*}} to i32
199 // CHECK-NEXT: call ptr asm "foobar"
200 __asm__ ("foobar" : "=a" (addr) : "0" (c));
201 return addr;
204 // PR10299 - fpsr, fpcr
205 void t25(void)
207 __asm__ __volatile__( \
208 "finit" \
211 :"st","st(1)","st(2)","st(3)", \
212 "st(4)","st(5)","st(6)","st(7)", \
213 "fpsr","fpcr" \
217 // AVX registers
218 typedef long long __m256i __attribute__((__vector_size__(32)));
219 void t26 (__m256i *p) {
220 __asm__ volatile("vmovaps %0, %%ymm0" :: "m" (*(__m256i*)p) : "ymm0");
223 // Check to make sure the inline asm non-standard dialect attribute _not_ is
224 // emitted.
225 void t27(void) {
226 asm volatile("nop");
227 // CHECK: @t27
228 // CHECK: call void asm sideeffect "nop"
229 // CHECK-NOT: ia_nsdialect
230 // CHECK: ret void
233 // Check handling of '*' and '#' constraint modifiers.
234 void t28(void)
236 asm volatile ("/* %0 */" : : "i#*X,*r" (1));
237 // CHECK: @t28
238 // CHECK: call void asm sideeffect "/* $0 */", "i|r,~{dirflag},~{fpsr},~{flags}"(i32 1)
241 static unsigned t29_var[1];
243 void t29(void) {
244 asm volatile("movl %%eax, %0"
246 : "m"(t29_var));
247 // CHECK: @t29
248 // CHECK: call void asm sideeffect "movl %eax, $0", "*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype([1 x i32]) @t29_var)
251 void t30(int len) {
252 __asm__ volatile(""
253 : "+&&rm"(len));
254 // CHECK: @t30
255 // CHECK: call void asm sideeffect "", "=*&rm,0,~{dirflag},~{fpsr},~{flags}"
258 void t31(int len) {
259 __asm__ volatile(""
260 : "+%%rm"(len), "+rm"(len));
261 // CHECK: @t31
262 // CHECK: call void asm sideeffect "", "=*%rm,=*rm,0,1,~{dirflag},~{fpsr},~{flags}"
265 // CHECK: @t32
266 int t32(int cond)
268 asm goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop);
269 // CHECK: callbr void asm sideeffect "testl $0, $0; jne ${1:l};", "r,!i,!i,~{dirflag},~{fpsr},~{flags}"(i32 %0) #1
270 // CHECK-NEXT: to label %asm.fallthrough [label %label_true, label %loop]
271 return 0;
272 loop:
273 return 0;
274 label_true:
275 return 1;
278 void *t33(void *ptr)
280 void *ret;
281 asm ("lea %1, %0" : "=r" (ret) : "p" (ptr));
282 return ret;
284 // CHECK: @t33
285 // CHECK: %1 = call ptr asm "lea $1, $0", "=r,p,~{dirflag},~{fpsr},~{flags}"(ptr %0)