blob: 4dc21e34be4abfe3103d8d1870db598227e49411 [file] [log] [blame]
Dan Gohman1cf96c02015-12-09 16:23:59 +00001; RUN: llc < %s -asm-verbose=false -verify-machineinstrs | FileCheck %s
Dan Gohman81719f82015-11-25 16:55:01 +00002
3; Test the register stackifier pass.
4
Dan Gohman0c6f5ac2016-01-07 03:19:23 +00005target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Dan Gohman81719f82015-11-25 16:55:01 +00006target triple = "wasm32-unknown-unknown"
7
8; No because of pointer aliasing.
9
10; CHECK-LABEL: no0:
11; CHECK: return $1{{$}}
12define i32 @no0(i32* %p, i32* %q) {
13 %t = load i32, i32* %q
14 store i32 0, i32* %p
15 ret i32 %t
16}
17
18; No because of side effects.
19
20; CHECK-LABEL: no1:
21; CHECK: return $1{{$}}
22define i32 @no1(i32* %p, i32* dereferenceable(4) %q) {
23 %t = load volatile i32, i32* %q, !invariant.load !0
24 store volatile i32 0, i32* %p
25 ret i32 %t
26}
27
28; Yes because of invariant load and no side effects.
29
30; CHECK-LABEL: yes0:
31; CHECK: return $pop0{{$}}
32define i32 @yes0(i32* %p, i32* dereferenceable(4) %q) {
33 %t = load i32, i32* %q, !invariant.load !0
34 store i32 0, i32* %p
35 ret i32 %t
36}
37
38; Yes because of no intervening side effects.
39
40; CHECK-LABEL: yes1:
41; CHECK: return $pop0{{$}}
42define i32 @yes1(i32* %q) {
43 %t = load volatile i32, i32* %q
44 ret i32 %t
45}
46
Dan Gohman4da4abd2015-12-05 00:51:40 +000047; Don't schedule stack uses into the stack. To reduce register pressure, the
48; scheduler might be tempted to move the definition of $2 down. However, this
49; would risk getting incorrect liveness if the instructions are later
50; rearranged to make the stack contiguous.
51
52; CHECK-LABEL: stack_uses:
Dan Gohmanf0b165a2015-12-05 03:03:35 +000053; CHECK-NEXT: .param i32, i32, i32, i32{{$}}
Dan Gohman4da4abd2015-12-05 00:51:40 +000054; CHECK-NEXT: .result i32{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000055; CHECK-NEXT: .local i32, i32{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000056; CHECK-NEXT: i32.const $5=, 2{{$}}
Dan Gohman8887d1f2015-12-25 00:31:02 +000057; CHECK-NEXT: i32.const $4=, 1{{$}}
58; CHECK-NEXT: block BB4_2{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000059; CHECK-NEXT: i32.lt_s $push0=, $0, $4{{$}}
60; CHECK-NEXT: i32.lt_s $push1=, $1, $5{{$}}
61; CHECK-NEXT: i32.xor $push4=, $pop0, $pop1{{$}}
62; CHECK-NEXT: i32.lt_s $push2=, $2, $4{{$}}
63; CHECK-NEXT: i32.lt_s $push3=, $3, $5{{$}}
64; CHECK-NEXT: i32.xor $push5=, $pop2, $pop3{{$}}
65; CHECK-NEXT: i32.xor $push6=, $pop4, $pop5{{$}}
66; CHECK-NEXT: i32.ne $push7=, $pop6, $4{{$}}
Dan Gohmanf0b165a2015-12-05 03:03:35 +000067; CHECK-NEXT: br_if $pop7, BB4_2{{$}}
68; CHECK-NEXT: i32.const $push8=, 0{{$}}
69; CHECK-NEXT: return $pop8{{$}}
70; CHECK-NEXT: BB4_2:
71; CHECK-NEXT: return $4{{$}}
72define i32 @stack_uses(i32 %x, i32 %y, i32 %z, i32 %w) {
Dan Gohman4da4abd2015-12-05 00:51:40 +000073entry:
Dan Gohmanf0b165a2015-12-05 03:03:35 +000074 %c = icmp sle i32 %x, 0
75 %d = icmp sle i32 %y, 1
76 %e = icmp sle i32 %z, 0
77 %f = icmp sle i32 %w, 1
78 %g = xor i1 %c, %d
79 %h = xor i1 %e, %f
80 %i = xor i1 %g, %h
81 br i1 %i, label %true, label %false
Dan Gohman4da4abd2015-12-05 00:51:40 +000082true:
83 ret i32 0
84false:
85 ret i32 1
86}
87
Dan Gohman8887d1f2015-12-25 00:31:02 +000088; Test an interesting case where the load has multiple uses and cannot
89; be trivially stackified.
90
91; CHECK-LABEL: multiple_uses:
92; CHECK-NEXT: .param i32, i32, i32{{$}}
93; CHECK-NEXT: .local i32{{$}}
94; CHECK-NEXT: i32.load $3=, 0($2){{$}}
95; CHECK-NEXT: block BB5_3{{$}}
96; CHECK-NEXT: i32.ge_u $push0=, $3, $1{{$}}
97; CHECK-NEXT: br_if $pop0, BB5_3{{$}}
98; CHECK-NEXT: i32.lt_u $push1=, $3, $0{{$}}
99; CHECK-NEXT: br_if $pop1, BB5_3{{$}}
100; CHECK-NEXT: i32.store $discard=, 0($2), $3{{$}}
101; CHECK-NEXT: BB5_3:
102; CHECK-NEXT: return{{$}}
103define void @multiple_uses(i32* %arg0, i32* %arg1, i32* %arg2) nounwind {
104bb:
105 br label %loop
106
107loop:
108 %tmp7 = load i32, i32* %arg2
109 %tmp8 = inttoptr i32 %tmp7 to i32*
110 %tmp9 = icmp uge i32* %tmp8, %arg1
111 %tmp10 = icmp ult i32* %tmp8, %arg0
112 %tmp11 = or i1 %tmp9, %tmp10
113 br i1 %tmp11, label %back, label %then
114
115then:
116 store i32 %tmp7, i32* %arg2
117 br label %back
118
119back:
120 br i1 undef, label %return, label %loop
121
122return:
123 ret void
124}
125
Dan Gohman81719f82015-11-25 16:55:01 +0000126!0 = !{}