blob: 180d70e2e4a7071cae3126432bc8bf9a11041e9c [file] [log] [blame]
Dan Gohman81719f82015-11-25 16:55:01 +00001; RUN: llc < %s -asm-verbose=false | FileCheck %s
2
3; Test the register stackifier pass.
4
5target datalayout = "e-p:32:32-i64:64-n32:64-S128"
6target 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:
53; CHECK-NEXT: .param i32{{$}}
54; CHECK-NEXT: .result i32{{$}}
55; CHECK-NEXT: local i32, i32{{$}}
56; CHECK-NEXT: i32.const $1=, 1{{$}}
57; CHECK-NEXT: i32.const $2=, 0{{$}}
58; CHECK-NEXT: i32.and $push0=, $0, $1{{$}}
59; CHECK-NEXT: i32.eq $push1=, $pop0, $2{{$}}
60; CHECK-NEXT: block BB4_2{{$}}
61; CHECK-NEXT: br_if $pop1, BB4_2{{$}}
62; CHECK-NEXT: return $2{{$}}
63; CHECK-NEXT: BB4_2:{{$}}
64; CHECK-NEXT: return $1{{$}}
65define i32 @stack_uses(i32 %x) {
66entry:
67 %c = trunc i32 %x to i1
68 br i1 %c, label %true, label %false
69true:
70 ret i32 0
71false:
72 ret i32 1
73}
74
Dan Gohman81719f82015-11-25 16:55:01 +000075!0 = !{}