xref: /llvm-project/llvm/test/Transforms/SimplifyCFG/PhiBlockMerge2.ll (revision d1d129356909af2f6fefd6f1b9335a39fe172e9a)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; Test merging of blocks that only have PHI nodes in them.  This tests the case
3; where the mergedinto block doesn't have any PHI nodes, and is in fact
4; dominated by the block-to-be-eliminated
5;
6; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
7;
8
9declare i1 @foo()
10
11define i32 @test(i1 %a, i1 %b) {
12; CHECK-LABEL: @test(
13; CHECK-NEXT:    [[C:%.*]] = call i1 @foo()
14; CHECK-NEXT:    br i1 [[C]], label [[M:%.*]], label [[P:%.*]]
15; CHECK:       P:
16; CHECK-NEXT:    [[D:%.*]] = call i1 @foo()
17; CHECK-NEXT:    [[SPEC_SELECT:%.*]] = select i1 [[D]], i32 2, i32 1
18; CHECK-NEXT:    br label [[M]]
19; CHECK:       M:
20; CHECK-NEXT:    [[W:%.*]] = phi i32 [ 0, [[TMP0:%.*]] ], [ [[SPEC_SELECT]], [[P]] ]
21; CHECK-NEXT:    [[R:%.*]] = add i32 [[W]], 1
22; CHECK-NEXT:    ret i32 [[R]]
23;
24  %c = call i1 @foo()
25  br i1 %c, label %N, label %P
26P:
27  %d = call i1 @foo()
28  br i1 %d, label %N, label %Q
29Q:
30  br label %N
31N:
32  %W = phi i32 [0, %0], [1, %Q], [2, %P]
33  ; This block should be foldable into M
34  br label %M
35
36M:
37  %R = add i32 %W, 1
38  ret i32 %R
39}
40
41