1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instsimplify -S | FileCheck %s
3
4; PR12189
5define i1 @test1(i32 %x) {
6; CHECK-LABEL: @test1(
7; CHECK-NEXT:    br i1 true, label [[A:%.*]], label [[B:%.*]]
8; CHECK:       a:
9; CHECK-NEXT:    [[AA:%.*]] = or i32 [[X:%.*]], 10
10; CHECK-NEXT:    br label [[C:%.*]]
11; CHECK:       b:
12; CHECK-NEXT:    [[BB:%.*]] = or i32 [[X]], 10
13; CHECK-NEXT:    br label [[C]]
14; CHECK:       c:
15; CHECK-NEXT:    [[CC:%.*]] = phi i32 [ [[BB]], [[B]] ], [ [[AA]], [[A]] ]
16; CHECK-NEXT:    [[D:%.*]] = urem i32 [[CC]], 2
17; CHECK-NEXT:    [[E:%.*]] = icmp eq i32 [[D]], 0
18; CHECK-NEXT:    ret i1 [[E]]
19;
20  br i1 true, label %a, label %b
21
22a:
23  %aa = or i32 %x, 10
24  br label %c
25
26b:
27  %bb = or i32 %x, 10
28  br label %c
29
30c:
31  %cc = phi i32 [ %bb, %b ], [%aa, %a ]
32  %d = urem i32 %cc, 2
33  %e = icmp eq i32 %d, 0
34  ret i1 %e
35}
36
37; D63489 - https://reviews.llvm.org/D63489
38; If this single-value phi form needs to be preserved to enable
39; further analysis, then -instsimplify should not be running?
40
41define i32 @lcssa-phi(i32 %x) {
42; CHECK-LABEL: @lcssa-phi(
43; CHECK-NEXT:  entry:
44; CHECK-NEXT:    br label [[END:%.*]]
45; CHECK:       end:
46; CHECK-NEXT:    ret i32 [[X:%.*]]
47;
48entry:
49  br label %end
50
51end:
52  %counter.lcssa = phi i32 [ %x, %entry ]
53  ret i32 %counter.lcssa
54}
55
56define i32 @poison(i1 %cond, i32 %v) {
57; CHECK-LABEL: @poison(
58; CHECK-NEXT:    br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
59; CHECK:       A:
60; CHECK-NEXT:    br label [[EXIT:%.*]]
61; CHECK:       B:
62; CHECK-NEXT:    br label [[EXIT]]
63; CHECK:       EXIT:
64; CHECK-NEXT:    ret i32 [[V:%.*]]
65;
66  br i1 %cond, label %A, label %B
67A:
68  br label %EXIT
69B:
70  br label %EXIT
71EXIT:
72  %w = phi i32 [%v, %A], [poison, %B]
73  ret i32 %w
74}
75