1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc // PR10415 4*f4a2713aSLionel Sambuc __asm__ ("foo1"); 5*f4a2713aSLionel Sambuc __asm__ ("foo2"); 6*f4a2713aSLionel Sambuc __asm__ ("foo3"); 7*f4a2713aSLionel Sambuc // CHECK: module asm "foo1" 8*f4a2713aSLionel Sambuc // CHECK-NEXT: module asm "foo2" 9*f4a2713aSLionel Sambuc // CHECK-NEXT: module asm "foo3" 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc void t1(int len) { 12*f4a2713aSLionel Sambuc __asm__ volatile("" : "=&r"(len), "+&r"(len)); 13*f4a2713aSLionel Sambuc } 14*f4a2713aSLionel Sambuc 15*f4a2713aSLionel Sambuc void t2(unsigned long long t) { 16*f4a2713aSLionel Sambuc __asm__ volatile("" : "+m"(t)); 17*f4a2713aSLionel Sambuc } 18*f4a2713aSLionel Sambuc 19*f4a2713aSLionel Sambuc void t3(unsigned char *src, unsigned long long temp) { 20*f4a2713aSLionel Sambuc __asm__ volatile("" : "+m"(temp), "+r"(src)); 21*f4a2713aSLionel Sambuc } 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuc void t4() { 24*f4a2713aSLionel Sambuc unsigned long long a; 25*f4a2713aSLionel Sambuc struct reg { unsigned long long a, b; } b; 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambuc __asm__ volatile ("":: "m"(a), "m"(b)); 28*f4a2713aSLionel Sambuc } 29*f4a2713aSLionel Sambuc 30*f4a2713aSLionel Sambuc // PR3417 31*f4a2713aSLionel Sambuc void t5(int i) { 32*f4a2713aSLionel Sambuc asm("nop" : "=r"(i) : "0"(t5)); 33*f4a2713aSLionel Sambuc } 34*f4a2713aSLionel Sambuc 35*f4a2713aSLionel Sambuc // PR3641 36*f4a2713aSLionel Sambuc void t6(void) { 37*f4a2713aSLionel Sambuc __asm__ volatile("" : : "i" (t6)); 38*f4a2713aSLionel Sambuc } 39*f4a2713aSLionel Sambuc 40*f4a2713aSLionel Sambuc void t7(int a) { 41*f4a2713aSLionel Sambuc __asm__ volatile("T7 NAMED: %[input]" : "+r"(a): [input] "i" (4)); 42*f4a2713aSLionel Sambuc // CHECK: @t7(i32 43*f4a2713aSLionel Sambuc // CHECK: T7 NAMED: $1 44*f4a2713aSLionel Sambuc } 45*f4a2713aSLionel Sambuc 46*f4a2713aSLionel Sambuc void t8() { 47*f4a2713aSLionel Sambuc __asm__ volatile("T8 NAMED MODIFIER: %c[input]" :: [input] "i" (4)); 48*f4a2713aSLionel Sambuc // CHECK: @t8() 49*f4a2713aSLionel Sambuc // CHECK: T8 NAMED MODIFIER: ${0:c} 50*f4a2713aSLionel Sambuc } 51*f4a2713aSLionel Sambuc 52*f4a2713aSLionel Sambuc // PR3682 53*f4a2713aSLionel Sambuc unsigned t9(unsigned int a) { 54*f4a2713aSLionel Sambuc asm("bswap %0 %1" : "+r" (a)); 55*f4a2713aSLionel Sambuc return a; 56*f4a2713aSLionel Sambuc } 57*f4a2713aSLionel Sambuc 58*f4a2713aSLionel Sambuc // PR3908 59*f4a2713aSLionel Sambuc void t10(int r) { 60*f4a2713aSLionel Sambuc __asm__("PR3908 %[lf] %[xx] %[li] %[r]" : [r] "+r" (r) : [lf] "mx" (0), [li] "mr" (0), [xx] "x" ((double)(0))); 61*f4a2713aSLionel Sambuc 62*f4a2713aSLionel Sambuc // CHECK: @t10( 63*f4a2713aSLionel Sambuc // CHECK:PR3908 $1 $3 $2 $0 64*f4a2713aSLionel Sambuc } 65*f4a2713aSLionel Sambuc 66*f4a2713aSLionel Sambuc // PR3373 67*f4a2713aSLionel Sambuc unsigned t11(signed char input) { 68*f4a2713aSLionel Sambuc unsigned output; 69*f4a2713aSLionel Sambuc __asm__("xyz" 70*f4a2713aSLionel Sambuc : "=a" (output) 71*f4a2713aSLionel Sambuc : "0" (input)); 72*f4a2713aSLionel Sambuc return output; 73*f4a2713aSLionel Sambuc } 74*f4a2713aSLionel Sambuc 75*f4a2713aSLionel Sambuc // PR3373 76*f4a2713aSLionel Sambuc unsigned char t12(unsigned input) { 77*f4a2713aSLionel Sambuc unsigned char output; 78*f4a2713aSLionel Sambuc __asm__("xyz" 79*f4a2713aSLionel Sambuc : "=a" (output) 80*f4a2713aSLionel Sambuc : "0" (input)); 81*f4a2713aSLionel Sambuc return output; 82*f4a2713aSLionel Sambuc } 83*f4a2713aSLionel Sambuc 84*f4a2713aSLionel Sambuc unsigned char t13(unsigned input) { 85*f4a2713aSLionel Sambuc unsigned char output; 86*f4a2713aSLionel Sambuc __asm__("xyz %1" 87*f4a2713aSLionel Sambuc : "=a" (output) 88*f4a2713aSLionel Sambuc : "0" (input)); 89*f4a2713aSLionel Sambuc return output; 90*f4a2713aSLionel Sambuc } 91*f4a2713aSLionel Sambuc 92*f4a2713aSLionel Sambuc struct large { 93*f4a2713aSLionel Sambuc int x[1000]; 94*f4a2713aSLionel Sambuc }; 95*f4a2713aSLionel Sambuc 96*f4a2713aSLionel Sambuc unsigned long t15(int x, struct large *P) { 97*f4a2713aSLionel Sambuc __asm__("xyz " 98*f4a2713aSLionel Sambuc : "=r" (x) 99*f4a2713aSLionel Sambuc : "m" (*P), "0" (x)); 100*f4a2713aSLionel Sambuc return x; 101*f4a2713aSLionel Sambuc } 102*f4a2713aSLionel Sambuc 103*f4a2713aSLionel Sambuc // bitfield destination of an asm. 104*f4a2713aSLionel Sambuc struct S { 105*f4a2713aSLionel Sambuc int a : 4; 106*f4a2713aSLionel Sambuc }; 107*f4a2713aSLionel Sambuc 108*f4a2713aSLionel Sambuc void t14(struct S *P) { 109*f4a2713aSLionel Sambuc __asm__("abc %0" : "=r"(P->a) ); 110*f4a2713aSLionel Sambuc } 111*f4a2713aSLionel Sambuc 112*f4a2713aSLionel Sambuc // PR4938 113*f4a2713aSLionel Sambuc int t16() { 114*f4a2713aSLionel Sambuc int a,b; 115*f4a2713aSLionel Sambuc asm ( "nop;" 116*f4a2713aSLionel Sambuc :"=%c" (a) 117*f4a2713aSLionel Sambuc : "r" (b) 118*f4a2713aSLionel Sambuc ); 119*f4a2713aSLionel Sambuc return 0; 120*f4a2713aSLionel Sambuc } 121*f4a2713aSLionel Sambuc 122*f4a2713aSLionel Sambuc // PR6475 123*f4a2713aSLionel Sambuc void t17() { 124*f4a2713aSLionel Sambuc int i; 125*f4a2713aSLionel Sambuc __asm__ ( "nop": "=m"(i)); 126*f4a2713aSLionel Sambuc 127*f4a2713aSLionel Sambuc // CHECK: @t17() 128*f4a2713aSLionel Sambuc // CHECK: call void asm "nop", "=*m, 129*f4a2713aSLionel Sambuc } 130*f4a2713aSLionel Sambuc 131*f4a2713aSLionel Sambuc // <rdar://problem/6841383> 132*f4a2713aSLionel Sambuc int t18(unsigned data) { 133*f4a2713aSLionel Sambuc int a, b; 134*f4a2713aSLionel Sambuc 135*f4a2713aSLionel Sambuc asm("xyz" :"=a"(a), "=d"(b) : "a"(data)); 136*f4a2713aSLionel Sambuc return a + b; 137*f4a2713aSLionel Sambuc // CHECK: t18(i32 138*f4a2713aSLionel Sambuc // CHECK: = call {{.*}}asm "xyz" 139*f4a2713aSLionel Sambuc // CHECK-NEXT: extractvalue 140*f4a2713aSLionel Sambuc // CHECK-NEXT: extractvalue 141*f4a2713aSLionel Sambuc } 142*f4a2713aSLionel Sambuc 143*f4a2713aSLionel Sambuc // PR6780 144*f4a2713aSLionel Sambuc int t19(unsigned data) { 145*f4a2713aSLionel Sambuc int a, b; 146*f4a2713aSLionel Sambuc 147*f4a2713aSLionel Sambuc asm("x{abc|def|ghi}z" :"=r"(a): "r"(data)); 148*f4a2713aSLionel Sambuc return a + b; 149*f4a2713aSLionel Sambuc // CHECK: t19(i32 150*f4a2713aSLionel Sambuc // CHECK: = call {{.*}}asm "x$(abc$|def$|ghi$)z" 151*f4a2713aSLionel Sambuc } 152*f4a2713aSLionel Sambuc 153*f4a2713aSLionel Sambuc // PR6845 - Mismatching source/dest fp types. 154*f4a2713aSLionel Sambuc double t20(double x) { 155*f4a2713aSLionel Sambuc register long double result; 156*f4a2713aSLionel Sambuc __asm __volatile ("frndint" : "=t" (result) : "0" (x)); 157*f4a2713aSLionel Sambuc return result; 158*f4a2713aSLionel Sambuc 159*f4a2713aSLionel Sambuc // CHECK: @t20 160*f4a2713aSLionel Sambuc // CHECK: fpext double {{.*}} to x86_fp80 161*f4a2713aSLionel Sambuc // CHECK-NEXT: call x86_fp80 asm sideeffect "frndint" 162*f4a2713aSLionel Sambuc // CHECK: fptrunc x86_fp80 {{.*}} to double 163*f4a2713aSLionel Sambuc } 164*f4a2713aSLionel Sambuc 165*f4a2713aSLionel Sambuc float t21(long double x) { 166*f4a2713aSLionel Sambuc register float result; 167*f4a2713aSLionel Sambuc __asm __volatile ("frndint" : "=t" (result) : "0" (x)); 168*f4a2713aSLionel Sambuc return result; 169*f4a2713aSLionel Sambuc // CHECK: @t21 170*f4a2713aSLionel Sambuc // CHECK: call x86_fp80 asm sideeffect "frndint" 171*f4a2713aSLionel Sambuc // CHECK-NEXT: fptrunc x86_fp80 {{.*}} to float 172*f4a2713aSLionel Sambuc } 173*f4a2713aSLionel Sambuc 174*f4a2713aSLionel Sambuc // <rdar://problem/8348447> - accept 'l' constraint 175*f4a2713aSLionel Sambuc unsigned char t22(unsigned char a, unsigned char b) { 176*f4a2713aSLionel Sambuc unsigned int la = a; 177*f4a2713aSLionel Sambuc unsigned int lb = b; 178*f4a2713aSLionel Sambuc unsigned int bigres; 179*f4a2713aSLionel Sambuc unsigned char res; 180*f4a2713aSLionel Sambuc __asm__ ("0:\n1:\n" : [bigres] "=la"(bigres) : [la] "0"(la), [lb] "c"(lb) : 181*f4a2713aSLionel Sambuc "edx", "cc"); 182*f4a2713aSLionel Sambuc res = bigres; 183*f4a2713aSLionel Sambuc return res; 184*f4a2713aSLionel Sambuc } 185*f4a2713aSLionel Sambuc 186*f4a2713aSLionel Sambuc // <rdar://problem/8348447> - accept 'l' constraint 187*f4a2713aSLionel Sambuc unsigned char t23(unsigned char a, unsigned char b) { 188*f4a2713aSLionel Sambuc unsigned int la = a; 189*f4a2713aSLionel Sambuc unsigned int lb = b; 190*f4a2713aSLionel Sambuc unsigned char res; 191*f4a2713aSLionel Sambuc __asm__ ("0:\n1:\n" : [res] "=la"(res) : [la] "0"(la), [lb] "c"(lb) : 192*f4a2713aSLionel Sambuc "edx", "cc"); 193*f4a2713aSLionel Sambuc return res; 194*f4a2713aSLionel Sambuc } 195*f4a2713aSLionel Sambuc 196*f4a2713aSLionel Sambuc void *t24(char c) { 197*f4a2713aSLionel Sambuc void *addr; 198*f4a2713aSLionel Sambuc // CHECK: @t24 199*f4a2713aSLionel Sambuc // CHECK: zext i8 {{.*}} to i32 200*f4a2713aSLionel Sambuc // CHECK-NEXT: call i8* asm "foobar" 201*f4a2713aSLionel Sambuc __asm__ ("foobar" : "=a" (addr) : "0" (c)); 202*f4a2713aSLionel Sambuc return addr; 203*f4a2713aSLionel Sambuc } 204*f4a2713aSLionel Sambuc 205*f4a2713aSLionel Sambuc // PR10299 - fpsr, fpcr 206*f4a2713aSLionel Sambuc void t25(void) 207*f4a2713aSLionel Sambuc { 208*f4a2713aSLionel Sambuc __asm__ __volatile__( \ 209*f4a2713aSLionel Sambuc "finit" \ 210*f4a2713aSLionel Sambuc : \ 211*f4a2713aSLionel Sambuc : \ 212*f4a2713aSLionel Sambuc :"st","st(1)","st(2)","st(3)", \ 213*f4a2713aSLionel Sambuc "st(4)","st(5)","st(6)","st(7)", \ 214*f4a2713aSLionel Sambuc "fpsr","fpcr" \ 215*f4a2713aSLionel Sambuc ); 216*f4a2713aSLionel Sambuc } 217*f4a2713aSLionel Sambuc 218*f4a2713aSLionel Sambuc // rdar://10510405 - AVX registers 219*f4a2713aSLionel Sambuc typedef long long __m256i __attribute__((__vector_size__(32))); 220*f4a2713aSLionel Sambuc void t26 (__m256i *p) { 221*f4a2713aSLionel Sambuc __asm__ volatile("vmovaps %0, %%ymm0" :: "m" (*(__m256i*)p) : "ymm0"); 222*f4a2713aSLionel Sambuc } 223*f4a2713aSLionel Sambuc 224*f4a2713aSLionel Sambuc // Check to make sure the inline asm non-standard dialect attribute _not_ is 225*f4a2713aSLionel Sambuc // emitted. 226*f4a2713aSLionel Sambuc void t27(void) { 227*f4a2713aSLionel Sambuc asm volatile("nop"); 228*f4a2713aSLionel Sambuc // CHECK: @t27 229*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect "nop" 230*f4a2713aSLionel Sambuc // CHECK-NOT: ia_nsdialect 231*f4a2713aSLionel Sambuc // CHECK: ret void 232*f4a2713aSLionel Sambuc } 233*f4a2713aSLionel Sambuc 234*f4a2713aSLionel Sambuc // Check handling of '*' and '#' constraint modifiers. 235*f4a2713aSLionel Sambuc void t28(void) 236*f4a2713aSLionel Sambuc { 237*f4a2713aSLionel Sambuc asm volatile ("/* %0 */" : : "i#*X,*r" (1)); 238*f4a2713aSLionel Sambuc // CHECK: @t28 239*f4a2713aSLionel Sambuc // CHECK: call void asm sideeffect "/* $0 */", "i|r,~{dirflag},~{fpsr},~{flags}"(i32 1) 240*f4a2713aSLionel Sambuc } 241*f4a2713aSLionel Sambuc 242