1; RUN: llc < %s -mtriple=i686-- -mcpu=core2 -no-integrated-as | FileCheck %s 2 3define i32 @t1() nounwind { 4entry: 5 %0 = tail call i32 asm sideeffect inteldialect "mov eax, $1\0A\09mov $0, eax", "=r,r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32 1) nounwind 6 ret i32 %0 7; CHECK: t1 8; CHECK: {{## InlineAsm Start|#APP}} 9; CHECK: .intel_syntax 10; CHECK: mov eax, ecx 11; CHECK: mov ecx, eax 12; CHECK: .att_syntax 13; CHECK: {{## InlineAsm End|#NO_APP}} 14} 15 16define void @t2() nounwind { 17entry: 18 call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind 19 ret void 20; CHECK: t2 21; CHECK: {{## InlineAsm Start|#APP}} 22; CHECK: .intel_syntax 23; CHECK: mov eax, 1 24; CHECK: .att_syntax 25; CHECK: {{## InlineAsm End|#NO_APP}} 26} 27 28define void @t3(i32 %V) nounwind { 29entry: 30 %V.addr = alloca i32, align 4 31 store i32 %V, ptr %V.addr, align 4 32 call void asm sideeffect inteldialect "mov eax, DWORD PTR [$0]", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i32) %V.addr) nounwind 33 ret void 34; CHECK: t3 35; CHECK: {{## InlineAsm Start|#APP}} 36; CHECK: .intel_syntax 37; CHECK: mov eax, DWORD PTR {{[[esp]}} 38; CHECK: .att_syntax 39; CHECK: {{## InlineAsm End|#NO_APP}} 40} 41 42%struct.t18_type = type { i32, i32 } 43 44define i32 @t18() nounwind { 45entry: 46 %foo = alloca %struct.t18_type, align 4 47 store i32 1, ptr %foo, align 4 48 %b = getelementptr inbounds %struct.t18_type, ptr %foo, i32 0, i32 1 49 store i32 2, ptr %b, align 4 50 call void asm sideeffect inteldialect "lea ebx, foo\0A\09mov eax, [ebx].0\0A\09mov [ebx].4, ecx", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind 51 %b1 = getelementptr inbounds %struct.t18_type, ptr %foo, i32 0, i32 1 52 %0 = load i32, ptr %b1, align 4 53 ret i32 %0 54; CHECK: t18 55; CHECK: {{## InlineAsm Start|#APP}} 56; CHECK: .intel_syntax 57; CHECK: lea ebx, foo 58; CHECK: mov eax, [ebx].0 59; CHECK: mov [ebx].4, ecx 60; CHECK: .att_syntax 61; CHECK: {{## InlineAsm End|#NO_APP}} 62} 63 64define void @t19_helper() nounwind { 65entry: 66 ret void 67} 68 69define void @t19() nounwind { 70entry: 71 call void asm sideeffect inteldialect "call $0", "r,~{dirflag},~{fpsr},~{flags}"(ptr @t19_helper) nounwind 72 ret void 73; CHECK-LABEL: t19: 74; CHECK: movl ${{_?}}t19_helper, %eax 75; CHECK: {{## InlineAsm Start|#APP}} 76; CHECK: .intel_syntax 77; CHECK: call eax 78; CHECK: .att_syntax 79; CHECK: {{## InlineAsm End|#NO_APP}} 80} 81 82@results = global [2 x i32] [i32 3, i32 2], align 4 83 84define ptr @t30() nounwind ssp { 85entry: 86 %res = alloca ptr, align 4 87 call void asm sideeffect inteldialect "lea edi, dword ptr $0", "*m,~{edi},~{dirflag},~{fpsr},~{flags}"(ptr elementtype([2 x i32]) @results) nounwind 88 call void asm sideeffect inteldialect "mov dword ptr $0, edi", "=*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(ptr) %res) nounwind 89 %0 = load ptr, ptr %res, align 4 90 ret ptr %0 91; CHECK-LABEL: t30: 92; CHECK: {{## InlineAsm Start|#APP}} 93; CHECK: .intel_syntax 94; CHECK: lea edi, dword ptr [{{_?}}results] 95; CHECK: .att_syntax 96; CHECK: {{## InlineAsm End|#NO_APP}} 97; CHECK: {{## InlineAsm Start|#APP}} 98; CHECK: .intel_syntax 99; CHECK: mov dword ptr [esp], edi 100; CHECK: .att_syntax 101; CHECK: {{## InlineAsm End|#NO_APP}} 102; CHECK: movl (%esp), %eax 103} 104 105; Stack realignment plus MS inline asm that does *not* adjust the stack is no 106; longer an error. 107 108define i32 @t31() { 109entry: 110 %val = alloca i32, align 64 111 store i32 -1, ptr %val, align 64 112 call void asm sideeffect inteldialect "mov dword ptr $0, esp", "=*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i32) %val) 113 %sp = load i32, ptr %val, align 64 114 ret i32 %sp 115; CHECK-LABEL: t31: 116; CHECK: pushl %ebp 117; CHECK: movl %esp, %ebp 118; CHECK: andl $-64, %esp 119; CHECK: {{## InlineAsm Start|#APP}} 120; CHECK: .intel_syntax 121; CHECK: mov dword ptr [esp], esp 122; CHECK: .att_syntax 123; CHECK: {{## InlineAsm End|#NO_APP}} 124; CHECK: movl (%esp), %eax 125; CHECK: ret 126} 127 128; Make sure ${:uid} works. Clang uses it for MS inline asm labels. 129; 130; C source: 131; int uid() { 132; int r; 133; __asm { 134; xor eax, eax 135; wloop: 136; inc eax 137; cmp eax, 42 138; jne wloop 139; mov r, eax 140; } 141; return r; 142; } 143define i32 @uid() { 144entry: 145 %r = alloca i32, align 4 146 call void asm sideeffect inteldialect "xor eax, eax\0A\09.L__MSASMLABEL_.${:uid}__wloop:\0A\09inc eax\0A\09cmp eax, $$42\0A\09jne .L__MSASMLABEL_.${:uid}__wloop\0A\09mov dword ptr $0, eax", "=*m,~{eax},~{flags},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i32) nonnull %r) 147 %0 = load i32, ptr %r, align 4 148 ret i32 %0 149; CHECK-LABEL: uid: 150; CHECK: {{## InlineAsm Start|#APP}} 151; CHECK: .L__MSASMLABEL_.0__wloop: 152; CHECK: jne .L__MSASMLABEL_.0__wloop 153; CHECK: .att_syntax 154; CHECK: {{## InlineAsm End|#NO_APP}} 155; CHECK: ret 156} 157 158declare hidden void @other_func() 159 160define void @naked() #0 { 161 call void asm sideeffect inteldialect "call dword ptr $0", "*m,~{eax},~{ebx},~{ecx},~{edx},~{edi},~{esi},~{esp},~{ebp},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(void()) @other_func) 162 unreachable 163} 164 165attributes #0 = { naked } 166