1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -no-integrated-as -verify-machineinstrs | FileCheck %s
3 ; Test basic inline assembly. Pass -no-integrated-as since these aren't
4 ; actually valid assembly syntax.
6 target triple = "wasm32-unknown-unknown"
9 ; CHECK-NEXT: .functype foo (i32) -> (i32){{$}}
10 ; CHECK-NEXT: #APP{{$}}
11 ; CHECK-NEXT: # 0 = aaa(0){{$}}
12 ; CHECK-NEXT: #NO_APP{{$}}
13 ; CHECK-NEXT: local.get $push0=, 0{{$}}
14 ; CHECK-NEXT: return $pop0{{$}}
15 define i32 @foo(i32 %r) {
17 %0 = tail call i32 asm sideeffect "# $0 = aaa($1)", "=r,r"(i32 %r) #0, !srcloc !0
22 ; CHECK-NEXT: .functype imm () -> (i32){{$}}
23 ; CHECK-NEXT: .local i32{{$}}
24 ; CHECK-NEXT: #APP{{$}}
25 ; CHECK-NEXT: # 0 = ccc(42){{$}}
26 ; CHECK-NEXT: #NO_APP{{$}}
27 ; CHECK-NEXT: local.get $push0=, 0{{$}}
28 ; CHECK-NEXT: return $pop0{{$}}
31 %0 = tail call i32 asm sideeffect "# $0 = ccc($1)", "=r,i"(i32 42) #0, !srcloc !2
35 ; CHECK-LABEL: foo_i64:
36 ; CHECK-NEXT: .functype foo_i64 (i64) -> (i64){{$}}
37 ; CHECK-NEXT: #APP{{$}}
38 ; CHECK-NEXT: # 0 = aaa(0){{$}}
39 ; CHECK-NEXT: #NO_APP{{$}}
40 ; CHECK-NEXT: local.get $push0=, 0{{$}}
41 ; CHECK-NEXT: return $pop0{{$}}
42 define i64 @foo_i64(i64 %r) {
44 %0 = tail call i64 asm sideeffect "# $0 = aaa($1)", "=r,r"(i64 %r) #0, !srcloc !0
48 ; CHECK-LABEL: foo_float:
49 ; CHECK-NEXT: .functype foo_float (f32) -> (f32){{$}}
50 ; CHECK-NEXT: #APP{{$}}
51 ; CHECK-NEXT: # 0 = aaa(0){{$}}
52 ; CHECK-NEXT: #NO_APP{{$}}
53 ; CHECK-NEXT: local.get $push0=, 0{{$}}
54 ; CHECK-NEXT: return $pop0{{$}}
55 define float @foo_float(float %r) {
57 %0 = tail call float asm sideeffect "# $0 = aaa($1)", "=r,r"(float %r) #0, !srcloc !0
61 ; CHECK-LABEL: foo_double:
62 ; CHECK-NEXT: .functype foo_double (f64) -> (f64){{$}}
63 ; CHECK-NEXT: #APP{{$}}
64 ; CHECK-NEXT: # 0 = aaa(0){{$}}
65 ; CHECK-NEXT: #NO_APP{{$}}
66 ; CHECK-NEXT: local.get $push0=, 0{{$}}
67 ; CHECK-NEXT: return $pop0{{$}}
68 define double @foo_double(double %r) {
70 %0 = tail call double asm sideeffect "# $0 = aaa($1)", "=r,r"(double %r) #0, !srcloc !0
76 ; CHECK: local.get $push[[S0:[0-9]+]]=, 0{{$}}
77 ; CHECK-NEXT: local.get $push[[S1:[0-9]+]]=, 1{{$}}
78 ; CHECK-NEXT: i32.store16 0($pop[[S0]]), $pop[[S1]]{{$}}
79 define void @X_i16(ptr %t) {
80 call void asm sideeffect "foo $0", "=*X,~{dirflag},~{fpsr},~{flags},~{memory}"(ptr elementtype(i16) %t)
86 ; CHECK: local.get $push[[S0:[0-9]+]]=, 0{{$}}
87 ; CHECK-NEXT: local.get $push[[S1:[0-9]+]]=, 1{{$}}
88 ; CHECK-NEXT: i32.store 0($pop[[S0]]), $pop[[S1]]{{$}}
89 define void @X_ptr(ptr %t) {
90 call void asm sideeffect "foo $0", "=*X,~{dirflag},~{fpsr},~{flags},~{memory}"(ptr elementtype(ptr) %t)
94 ; CHECK-LABEL: funcname:
95 ; CHECK: foo funcname{{$}}
96 define void @funcname() {
97 tail call void asm sideeffect "foo $0", "i"(ptr nonnull @funcname) #0, !srcloc !0
101 ; CHECK-LABEL: varname:
102 ; CHECK: foo gv+37{{$}}
103 @gv = global [0 x i8] zeroinitializer
104 define void @varname() {
105 tail call void asm sideeffect "foo $0", "i"(ptr getelementptr inbounds ([0 x i8], ptr @gv, i64 0, i64 37)) #0, !srcloc !0
109 ; CHECK-LABEL: r_constraint
110 ; CHECK: i32.const $push[[S0:[0-9]+]]=, 0{{$}}
111 ; CHECK-NEXT: local.set [[L0:[0-9]+]], $pop[[S0]]{{$}}
112 ; CHECK-NEXT: i32.const $push[[S1:[0-9]+]]=, 37{{$}}
113 ; CHECK-NEXT: local.set [[L1:[0-9]+]], $pop[[S1]]{{$}}
114 ; CHECK: foo [[L2:[0-9]+]], 1, [[L0]], [[L1]]{{$}}
115 ; CHECK: local.get $push{{[0-9]+}}=, [[L2]]{{$}}
116 define hidden i32 @r_constraint(i32 %a, i32 %y) {
118 %z = bitcast i32 0 to i32
119 %t0 = tail call i32 asm "foo $0, $1, $2, $3", "=r,r,r,r"(i32 %y, i32 %z, i32 37) #0, !srcloc !0
123 ; CHECK-LABEL: tied_operands
124 ; CHECK: local.get $push0=, 0
125 ; CHECK: return $pop0
126 define i32 @tied_operands(i32 %var) {
128 %ret = call i32 asm "", "=r,0"(i32 %var)
132 attributes #0 = { nounwind }