[WebAssembly] Reintroduce ARGUMENT moving logic
[oota-llvm.git] / test / CodeGen / WebAssembly / phi.ll
1 ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs | 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 $[[NUM0:[0-9]+]]=, $0, $pop[[NUM1:[0-9]+]]{{$}}
12 ; CHECK: return $[[NUM0]]{{$}}
13 define i32 @test0(i32 %p) {
14 entry:
15   %t = icmp slt i32 %p, 0
16   br i1 %t, label %true, label %done
17 true:
18   %a = sdiv i32 %p, 3
19   br label %done
20 done:
21   %s = phi i32 [ %a, %true ], [ %p, %entry ]
22   ret i32 %s
23 }
24
25 ; Swap phis.
26
27 ; CHECK-LABEL: test1:
28 ; CHECK: BB1_1:
29 ; CHECK: copy_local $[[NUM0:[0-9]+]]=, $[[NUM1:[0-9]+]]{{$}}
30 ; CHECK: copy_local $[[NUM1]]=, $[[NUM2:[0-9]+]]{{$}}
31 ; CHECK: copy_local $[[NUM2]]=, $[[NUM0]]{{$}}
32 define i32 @test1(i32 %n) {
33 entry:
34   br label %loop
35
36 loop:
37   %a = phi i32 [ 0, %entry ], [ %b, %loop ]
38   %b = phi i32 [ 1, %entry ], [ %a, %loop ]
39   %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
40
41   %i.next = add i32 %i, 1
42   %t = icmp slt i32 %i.next, %n
43   br i1 %t, label %loop, label %exit
44
45 exit:
46   ret i32 %a
47 }