[WebAssembly] Reapply r252858, with svn add for the new file.
[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: div_s $push, (get_local 0), (get_local 3){{$}}
12 ; CHECK: set_local 0, $pop
13 ; CHECK: return (get_local 0)
14 define i32 @test0(i32 %p) {
15 entry:
16   %t = icmp slt i32 %p, 0
17   br i1 %t, label %true, label %done
18 true:
19   %a = sdiv i32 %p, 3
20   br label %done
21 done:
22   %s = phi i32 [ %a, %true ], [ %p, %entry ]
23   ret i32 %s
24 }
25
26 ; Swap phis.
27
28 ; CHECK-LABEL: test1:
29 ; CHECK: BB1_1:
30 ; CHECK: set_local [[REG0:.*]], (get_local [[REG1:.*]])
31 ; CHECK: set_local [[REG1]], (get_local [[REG2:.*]])
32 ; CHECK: set_local [[REG2]], (get_local [[REG0]])
33 define i32 @test1(i32 %n) {
34 entry:
35   br label %loop
36
37 loop:
38   %a = phi i32 [ 0, %entry ], [ %b, %loop ]
39   %b = phi i32 [ 1, %entry ], [ %a, %loop ]
40   %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
41
42   %i.next = add i32 %i, 1
43   %t = icmp slt i32 %i.next, %n
44   br i1 %t, label %loop, label %exit
45
46 exit:
47   ret i32 %a
48 }