blob: 95c10a68b9c20e92e62a73b5777b19b00c951055 [file] [log] [blame]
Dan Gohman045a2172018-09-04 17:46:12 +00001; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -no-integrated-as -verify-machineinstrs | FileCheck %s
Dan Gohmanf19ed562015-11-13 01:42:29 +00002
Dan Gohman0c6e3162016-01-12 21:01:30 +00003; Test basic inline assembly. Pass -no-integrated-as since these aren't
4; actually valid assembly syntax.
Dan Gohmanf19ed562015-11-13 01:42:29 +00005
Dan Gohman0c6f5ac2016-01-07 03:19:23 +00006target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Sam Clegga5908002018-05-10 17:49:11 +00007target triple = "wasm32-unknown-unknown"
Dan Gohmanf19ed562015-11-13 01:42:29 +00008
9; CHECK-LABEL: foo:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000010; CHECK-NEXT: .functype foo (i32) -> (i32){{$}}
Dan Gohmanf19ed562015-11-13 01:42:29 +000011; CHECK-NEXT: #APP{{$}}
Dan Gohmanb465aa02017-11-08 19:18:08 +000012; CHECK-NEXT: # 0 = aaa(0){{$}}
Dan Gohmanf19ed562015-11-13 01:42:29 +000013; CHECK-NEXT: #NO_APP{{$}}
Thomas Lively6a87dda2019-01-08 06:25:55 +000014; CHECK-NEXT: local.get $push0=, 0{{$}}
Dan Gohmanb465aa02017-11-08 19:18:08 +000015; CHECK-NEXT: return $pop0{{$}}
Dan Gohmanf19ed562015-11-13 01:42:29 +000016define i32 @foo(i32 %r) {
17entry:
Dan Gohman3d4a2062015-11-18 16:28:58 +000018 %0 = tail call i32 asm sideeffect "# $0 = aaa($1)", "=r,r"(i32 %r) #0, !srcloc !0
Dan Gohmanf19ed562015-11-13 01:42:29 +000019 ret i32 %0
20}
21
Dan Gohmanf19ed562015-11-13 01:42:29 +000022; CHECK-LABEL: imm:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000023; CHECK-NEXT: .functype imm () -> (i32){{$}}
Dan Gohmanb465aa02017-11-08 19:18:08 +000024; CHECK-NEXT: .local i32{{$}}
Dan Gohmanf19ed562015-11-13 01:42:29 +000025; CHECK-NEXT: #APP{{$}}
Dan Gohmanb465aa02017-11-08 19:18:08 +000026; CHECK-NEXT: # 0 = ccc(42){{$}}
Dan Gohmanf19ed562015-11-13 01:42:29 +000027; CHECK-NEXT: #NO_APP{{$}}
Thomas Lively6a87dda2019-01-08 06:25:55 +000028; CHECK-NEXT: local.get $push0=, 0{{$}}
Dan Gohmanb465aa02017-11-08 19:18:08 +000029; CHECK-NEXT: return $pop0{{$}}
Dan Gohmanf19ed562015-11-13 01:42:29 +000030define i32 @imm() {
31entry:
Dan Gohman3d4a2062015-11-18 16:28:58 +000032 %0 = tail call i32 asm sideeffect "# $0 = ccc($1)", "=r,i"(i32 42) #0, !srcloc !2
Dan Gohmanf19ed562015-11-13 01:42:29 +000033 ret i32 %0
34}
35
Dan Gohmana774d712015-11-25 22:28:50 +000036; CHECK-LABEL: foo_i64:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000037; CHECK-NEXT: .functype foo_i64 (i64) -> (i64){{$}}
Dan Gohmana774d712015-11-25 22:28:50 +000038; CHECK-NEXT: #APP{{$}}
Dan Gohmanb465aa02017-11-08 19:18:08 +000039; CHECK-NEXT: # 0 = aaa(0){{$}}
Dan Gohmana774d712015-11-25 22:28:50 +000040; CHECK-NEXT: #NO_APP{{$}}
Thomas Lively6a87dda2019-01-08 06:25:55 +000041; CHECK-NEXT: local.get $push0=, 0{{$}}
Dan Gohmanb465aa02017-11-08 19:18:08 +000042; CHECK-NEXT: return $pop0{{$}}
Dan Gohmana774d712015-11-25 22:28:50 +000043define i64 @foo_i64(i64 %r) {
44entry:
45 %0 = tail call i64 asm sideeffect "# $0 = aaa($1)", "=r,r"(i64 %r) #0, !srcloc !0
46 ret i64 %0
47}
48
Dan Gohman284384b2015-12-05 20:03:44 +000049; CHECK-LABEL: X_i16:
Dan Gohmanb465aa02017-11-08 19:18:08 +000050; CHECK: foo 1{{$}}
Thomas Lively6a87dda2019-01-08 06:25:55 +000051; CHECK: local.get $push[[S0:[0-9]+]]=, 0{{$}}
52; CHECK-NEXT: local.get $push[[S1:[0-9]+]]=, 1{{$}}
Dan Gohmanb465aa02017-11-08 19:18:08 +000053; CHECK-NEXT: i32.store16 0($pop[[S0]]), $pop[[S1]]{{$}}
Dan Gohman284384b2015-12-05 20:03:44 +000054define void @X_i16(i16 * %t) {
55 call void asm sideeffect "foo $0", "=*X,~{dirflag},~{fpsr},~{flags},~{memory}"(i16* %t)
56 ret void
57}
58
59; CHECK-LABEL: X_ptr:
Dan Gohmanb465aa02017-11-08 19:18:08 +000060; CHECK: foo 1{{$}}
Thomas Lively6a87dda2019-01-08 06:25:55 +000061; CHECK: local.get $push[[S0:[0-9]+]]=, 0{{$}}
62; CHECK-NEXT: local.get $push[[S1:[0-9]+]]=, 1{{$}}
Dan Gohmanb465aa02017-11-08 19:18:08 +000063; CHECK-NEXT: i32.store 0($pop[[S0]]), $pop[[S1]]{{$}}
Dan Gohman284384b2015-12-05 20:03:44 +000064define void @X_ptr(i16 ** %t) {
65 call void asm sideeffect "foo $0", "=*X,~{dirflag},~{fpsr},~{flags},~{memory}"(i16** %t)
66 ret void
67}
68
Dan Gohman30a42bf2015-12-16 17:15:17 +000069; CHECK-LABEL: funcname:
70; CHECK: foo funcname{{$}}
71define void @funcname() {
72 tail call void asm sideeffect "foo $0", "i"(void ()* nonnull @funcname) #0, !srcloc !0
73 ret void
74}
75
76; CHECK-LABEL: varname:
77; CHECK: foo gv+37{{$}}
78@gv = global [0 x i8] zeroinitializer
79define 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
81 ret void
82}
83
Dan Gohmanb465aa02017-11-08 19:18:08 +000084; CHECK-LABEL: r_constraint
85; CHECK: i32.const $push[[S0:[0-9]+]]=, 0{{$}}
Thomas Lively6a87dda2019-01-08 06:25:55 +000086; CHECK-NEXT: local.set [[L0:[0-9]+]], $pop[[S0]]{{$}}
Dan Gohmanb465aa02017-11-08 19:18:08 +000087; CHECK-NEXT: i32.const $push[[S1:[0-9]+]]=, 37{{$}}
Thomas Lively6a87dda2019-01-08 06:25:55 +000088; CHECK-NEXT: local.set [[L1:[0-9]+]], $pop[[S1]]{{$}}
Dan Gohmanb465aa02017-11-08 19:18:08 +000089; CHECK: foo [[L2:[0-9]+]], 1, [[L0]], [[L1]]{{$}}
Thomas Lively6a87dda2019-01-08 06:25:55 +000090; CHECK: local.get $push{{[0-9]+}}=, [[L2]]{{$}}
Dan Gohmanb465aa02017-11-08 19:18:08 +000091define hidden i32 @r_constraint(i32 %a, i32 %y) {
92entry:
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
95 ret i32 %t0
96}
97
Heejin Ahn300f42f2018-09-12 21:34:39 +000098; CHECK-LABEL: tied_operands
Thomas Lively6a87dda2019-01-08 06:25:55 +000099; CHECK: local.get $push0=, 0
Heejin Ahn300f42f2018-09-12 21:34:39 +0000100; CHECK: return $pop0
101define i32 @tied_operands(i32 %var) {
102entry:
103 %ret = call i32 asm "", "=r,0"(i32 %var)
104 ret i32 %ret
105}
106
Dan Gohmanf19ed562015-11-13 01:42:29 +0000107attributes #0 = { nounwind }
108
109!0 = !{i32 47}
110!1 = !{i32 145}
111!2 = !{i32 231}