39c3561bb2a427255d04c15430625263dc191b40
[oota-llvm.git] / test / CodeGen / WebAssembly / phi.ll
1 ; RUN: llc < %s -asm-verbose=false | FileCheck %s
2
3 ; Test that phis are lowered.
4
5 target datalayout = "e-p:32:32-i64:64-n32:64-S128"
6 target triple = "wasm32-unknown-unknown"
7
8 ; Basic phi triangle.
9
10 ; CHECK-LABEL: test0:
11 ; CHECK: get_local push, 0{{$}}
12 ; CHECK: set_local [[REG:.*]], pop
13 ; CHECK: div_s push, (get_local [[REG]]), {{.*}}
14 ; CHECK: set_local [[REG]], pop
15 ; CHECK: return (get_local [[REG]])
16 define i32 @test0(i32 %p) {
17 entry:
18   %t = icmp slt i32 %p, 0
19   br i1 %t, label %true, label %done
20 true:
21   %a = sdiv i32 %p, 3
22   br label %done
23 done:
24   %s = phi i32 [ %a, %true ], [ %p, %entry ]
25   ret i32 %s
26 }
27
28 ; Swap phis.
29
30 ; CHECK-LABEL: test1:
31 ; CHECK: BB1_1:
32 ; CHECK: get_local push, [[REG1:.*]]
33 ; CHECK: set_local [[REG0:.*]], pop
34 ; CHECK: get_local push, [[REG2:.*]]
35 ; CHECK: set_local [[REG1]], pop
36 ; CHECK: [[REG0]]
37 ; CHECK: set_local [[REG2]], pop
38 define i32 @test1(i32 %n) {
39 entry:
40   br label %loop
41
42 loop:
43   %a = phi i32 [ 0, %entry ], [ %b, %loop ]
44   %b = phi i32 [ 1, %entry ], [ %a, %loop ]
45   %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
46
47   %i.next = add i32 %i, 1
48   %t = icmp slt i32 %i.next, %n
49   br i1 %t, label %loop, label %exit
50
51 exit:
52   ret i32 %a
53 }