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 datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
7 target triple = "wasm32-unknown-unknown"
10 ; CHECK-NEXT: .functype foo (i32) -> (i32){{$}}
11 ; CHECK-NEXT: #APP{{$}}
12 ; CHECK-NEXT: # 0 = aaa(0){{$}}
13 ; CHECK-NEXT: #NO_APP{{$}}
14 ; CHECK-NEXT: local.get $push0=, 0{{$}}
15 ; CHECK-NEXT: return $pop0{{$}}
16 define i32 @foo(i32 %r) {
18 %0 = tail call i32 asm sideeffect "# $0 = aaa($1)", "=r,r"(i32 %r) #0, !srcloc !0
23 ; CHECK-NEXT: .functype imm () -> (i32){{$}}
24 ; CHECK-NEXT: .local i32{{$}}
25 ; CHECK-NEXT: #APP{{$}}
26 ; CHECK-NEXT: # 0 = ccc(42){{$}}
27 ; CHECK-NEXT: #NO_APP{{$}}
28 ; CHECK-NEXT: local.get $push0=, 0{{$}}
29 ; CHECK-NEXT: return $pop0{{$}}
32 %0 = tail call i32 asm sideeffect "# $0 = ccc($1)", "=r,i"(i32 42) #0, !srcloc !2
36 ; CHECK-LABEL: foo_i64:
37 ; CHECK-NEXT: .functype foo_i64 (i64) -> (i64){{$}}
38 ; CHECK-NEXT: #APP{{$}}
39 ; CHECK-NEXT: # 0 = aaa(0){{$}}
40 ; CHECK-NEXT: #NO_APP{{$}}
41 ; CHECK-NEXT: local.get $push0=, 0{{$}}
42 ; CHECK-NEXT: return $pop0{{$}}
43 define i64 @foo_i64(i64 %r) {
45 %0 = tail call i64 asm sideeffect "# $0 = aaa($1)", "=r,r"(i64 %r) #0, !srcloc !0
51 ; CHECK: local.get $push[[S0:[0-9]+]]=, 0{{$}}
52 ; CHECK-NEXT: local.get $push[[S1:[0-9]+]]=, 1{{$}}
53 ; CHECK-NEXT: i32.store16 0($pop[[S0]]), $pop[[S1]]{{$}}
54 define void @X_i16(i16 * %t) {
55 call void asm sideeffect "foo $0", "=*X,~{dirflag},~{fpsr},~{flags},~{memory}"(i16* %t)
61 ; CHECK: local.get $push[[S0:[0-9]+]]=, 0{{$}}
62 ; CHECK-NEXT: local.get $push[[S1:[0-9]+]]=, 1{{$}}
63 ; CHECK-NEXT: i32.store 0($pop[[S0]]), $pop[[S1]]{{$}}
64 define void @X_ptr(i16 ** %t) {
65 call void asm sideeffect "foo $0", "=*X,~{dirflag},~{fpsr},~{flags},~{memory}"(i16** %t)
69 ; CHECK-LABEL: funcname:
70 ; CHECK: foo funcname{{$}}
71 define void @funcname() {
72 tail call void asm sideeffect "foo $0", "i"(void ()* nonnull @funcname) #0, !srcloc !0
76 ; CHECK-LABEL: varname:
77 ; CHECK: foo gv+37{{$}}
78 @gv = global [0 x i8] zeroinitializer
79 define void @varname() {
80 tail call void asm sideeffect "foo $0", "i"(i8* getelementptr inbounds ([0 x i8], [0 x i8]* @gv, i64 0, i64 37)) #0, !srcloc !0
84 ; CHECK-LABEL: r_constraint
85 ; CHECK: i32.const $push[[S0:[0-9]+]]=, 0{{$}}
86 ; CHECK-NEXT: local.set [[L0:[0-9]+]], $pop[[S0]]{{$}}
87 ; CHECK-NEXT: i32.const $push[[S1:[0-9]+]]=, 37{{$}}
88 ; CHECK-NEXT: local.set [[L1:[0-9]+]], $pop[[S1]]{{$}}
89 ; CHECK: foo [[L2:[0-9]+]], 1, [[L0]], [[L1]]{{$}}
90 ; CHECK: local.get $push{{[0-9]+}}=, [[L2]]{{$}}
91 define hidden i32 @r_constraint(i32 %a, i32 %y) {
93 %z = bitcast i32 0 to i32
94 %t0 = tail call i32 asm "foo $0, $1, $2, $3", "=r,r,r,r"(i32 %y, i32 %z, i32 37) #0, !srcloc !0
98 ; CHECK-LABEL: tied_operands
99 ; CHECK: local.get $push0=, 0
100 ; CHECK: return $pop0
101 define i32 @tied_operands(i32 %var) {
103 %ret = call i32 asm "", "=r,0"(i32 %var)
107 attributes #0 = { nounwind }