xref: /llvm-project/llvm/test/CodeGen/WebAssembly/phi.ll (revision 122b0220fd45ee71acda912b0b712bb8edb6ba46)
1; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -verify-machineinstrs | FileCheck %s
2
3; Test that phis are lowered.
4
5target triple = "wasm32-unknown-unknown"
6
7; Basic phi triangle.
8
9; CHECK-LABEL: test0:
10; CHECK: div_s $[[NUM0:[0-9]+]]=, $0, $pop[[NUM1:[0-9]+]]{{$}}
11; CHECK: return $[[NUM0]]{{$}}
12define i32 @test0(i32 %p) {
13entry:
14  %t = icmp slt i32 %p, 0
15  br i1 %t, label %true, label %done
16true:
17  %a = sdiv i32 %p, 3
18  br label %done
19done:
20  %s = phi i32 [ %a, %true ], [ %p, %entry ]
21  ret i32 %s
22}
23
24; Swap phis.
25
26; CHECK-LABEL: test1:
27; CHECK: .LBB{{[0-9]+}}_1:
28; CHECK: local.copy $[[NUM0:[0-9]+]]=, $[[NUM1:[0-9]+]]{{$}}
29; CHECK: local.copy $[[NUM1]]=, $[[NUM2:[0-9]+]]{{$}}
30; CHECK: local.copy $[[NUM2]]=, $[[NUM0]]{{$}}
31define i32 @test1(i32 %n) {
32entry:
33  br label %loop
34
35loop:
36  %a = phi i32 [ 0, %entry ], [ %b, %loop ]
37  %b = phi i32 [ 1, %entry ], [ %a, %loop ]
38  %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
39
40  %i.next = add i32 %i, 1
41  %t = icmp slt i32 %i.next, %n
42  br i1 %t, label %loop, label %exit
43
44exit:
45  ret i32 %a
46}
47