xref: /llvm-project/llvm/test/CodeGen/X86/ms-inline-asm-functions.ll (revision 6b996282cee3588e46b18c30957e71c964012e14)
1;; Check that the generated memory references do not contain the `offset`
2;; operator. Use `-no-integrated-as` to disable AsmParser formatting.
3; RUN: llc -no-integrated-as -x86-asm-syntax=intel < %s | FileCheck %s
4
5;; This file was compiled from clang/test/CodeGen/ms-inline-asm-functions.c,
6;; using the following command line:
7;;
8;; bin/clang -cc1 -internal-isystem lib/clang/17/include -nostdsysteminc \
9;;           ../llvm-project/clang/test/CodeGen/ms-inline-asm-functions.c \
10;;           -triple i386-pc-windows-msvc -fms-extensions -S -o out.ll
11
12source_filename = "/llvm-project/clang/test/CodeGen/ms-inline-asm-functions.c"
13target datalayout = "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32-a:0:32-S32"
14target triple = "i386-pc-windows-msvc"
15
16@kptr = dso_local global ptr null, align 4
17
18; Function Attrs: noinline nounwind optnone
19define dso_local i32 @foo() #0 {
20entry:
21  %r = alloca ptr, align 4
22  %call = call ptr @gptr()
23  store ptr %call, ptr %r, align 4
24  %0 = call i32 asm sideeffect inteldialect "call ${1:P}\0A\09call $2\0A\09call ${3:P}\0A\09call $4", "={eax},*m,*m,*m,*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i32 (i32)) @k, ptr elementtype(ptr) %r, ptr elementtype(i32 (i32)) @kimport, ptr elementtype(ptr) @kptr) #3, !srcloc !4
25  ; CHECK-LABEL: _foo:
26  ; CHECK:      #APP
27  ; CHECK-NEXT: .intel_syntax
28  ; CHECK-NEXT: call _k
29  ; CHECK-NEXT: call [e{{([a-z]{2})}}]
30  ; CHECK-NEXT: call [e{{([a-z]{2})}}]
31  ; CHECK-NEXT: call [_kptr]
32  ; CHECK-NEXT: .att_syntax
33  ; CHECK-NEXT: #NO_APP
34  ret i32 %0
35}
36
37declare dso_local ptr @gptr()
38
39declare dso_local i32 @k(i32 noundef)
40
41declare dllimport i32 @kimport(i32 noundef)
42
43; Function Attrs: noinline nounwind optnone
44define dso_local i32 @bar() #0 {
45entry:
46  %0 = call i32 asm sideeffect inteldialect "jmp ${1:P}\0A\09ja ${2:P}\0A\09JAE ${3:P}\0A\09LOOP ${4:P}\0A\09loope ${5:P}\0A\09loopne ${6:P}", "={eax},*m,*m,*m,*m,*m,*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i32 (i32)) @k, ptr elementtype(i32 (i32)) @k, ptr elementtype(i32 (i32)) @k, ptr elementtype(i32 (i32)) @k, ptr elementtype(i32 (i32)) @k, ptr elementtype(i32 (i32)) @k) #3, !srcloc !5
47  ; CHECK-LABEL: _bar:
48  ; CHECK:      #APP
49  ; CHECK-NEXT: .intel_syntax
50  ; CHECK-NEXT: jmp _k
51  ; CHECK-NEXT: ja [_k]
52  ; CHECK-NEXT: JAE [_k]
53  ; CHECK-NEXT: LOOP [_k]
54  ; CHECK-NEXT: loope [_k]
55  ; CHECK-NEXT: loopne [_k]
56  ; CHECK-NEXT: .att_syntax
57  ; CHECK-NEXT: #NO_APP
58  ret i32 %0
59}
60
61; Function Attrs: noinline nounwind optnone
62define dso_local i32 @baz() #0 {
63entry:
64  %0 = call i32 asm sideeffect inteldialect "mov eax, $1\0A\09mov eax, $2", "=&{eax},*m,*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i32 (i32)) @k, ptr elementtype(ptr) @kptr) #3, !srcloc !6
65  ; CHECK-LABEL: _baz:
66  ; CHECK:      #APP
67  ; CHECK-NEXT: .intel_syntax
68  ; CHECK-NEXT: mov eax, [_k]
69  ; CHECK-NEXT: mov eax, [_kptr]
70  ; CHECK-NEXT: .att_syntax
71  ; CHECK-NEXT: #NO_APP
72  ret i32 %0
73}
74
75; Function Attrs: naked noinline nounwind optnone
76define dso_local void @naked() #2 {
77entry:
78  call void asm sideeffect inteldialect "pusha\0A\09call ${0:P}\0A\09popa\0A\09ret", "*m,~{eax},~{ebp},~{ebx},~{ecx},~{edi},~{edx},~{esi},~{esp},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i32 (i32)) @k) #3, !srcloc !7
79  ; CHECK-LABEL: _naked:
80  ; CHECK:      #APP
81  ; CHECK-NEXT: .intel_syntax
82  ; CHECK-NEXT: pusha
83  ; CHECK-NEXT: call _k
84  ; CHECK-NEXT: popa
85  ; CHECK-NEXT: ret
86  ; CHECK-NEXT: .att_syntax
87  ; CHECK-NEXT: #NO_APP
88  unreachable
89}
90
91attributes #0 = { noinline nounwind optnone }
92attributes #2 = { naked noinline nounwind optnone }
93attributes #3 = { nounwind }
94
95!llvm.module.flags = !{!0, !1, !2}
96!llvm.ident = !{!3}
97
98!0 = !{i32 1, !"NumRegisterParameters", i32 0}
99!1 = !{i32 1, !"wchar_size", i32 2}
100!2 = !{i32 1, !"MaxTLSAlign", i32 65536}
101!3 = !{!"clang version 17.0.0"}
102!4 = !{i64 528}
103!5 = !{i64 892}
104!6 = !{i64 1183}
105!7 = !{i64 1451}
106