1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
5 define i1 @test1(i32 %x) {
7 ; CHECK-NEXT: br i1 true, label [[A:%.*]], label [[B:%.*]]
9 ; CHECK-NEXT: [[AA:%.*]] = or i32 [[X:%.*]], 10
10 ; CHECK-NEXT: br label [[C:%.*]]
12 ; CHECK-NEXT: [[BB:%.*]] = or i32 [[X]], 10
13 ; CHECK-NEXT: br label [[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]]
20 br i1 true, label %a, label %b
31 %cc = phi i32 [ %bb, %b ], [%aa, %a ]
33 %e = icmp eq i32 %d, 0
37 ; D63489 - https://reviews.llvm.org/D63489
38 ; If this single-value phi form needs to be preserved to enable
39 ; further analysis, then -passes=instsimplify should not be running?
41 define i32 @lcssa-phi(i32 %x) {
42 ; CHECK-LABEL: @lcssa-phi(
44 ; CHECK-NEXT: br label [[END:%.*]]
46 ; CHECK-NEXT: ret i32 [[X:%.*]]
52 %counter.lcssa = phi i32 [ %x, %entry ]
53 ret i32 %counter.lcssa
56 define i32 @poison(i1 %cond, i32 %v) {
57 ; CHECK-LABEL: @poison(
58 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
60 ; CHECK-NEXT: br label [[EXIT:%.*]]
62 ; CHECK-NEXT: br label [[EXIT]]
64 ; CHECK-NEXT: ret i32 [[V:%.*]]
66 br i1 %cond, label %A, label %B
72 %w = phi i32 [%v, %A], [poison, %B]
76 define i32 @undef(i1 %cond, i32 %v) {
77 ; CHECK-LABEL: @undef(
78 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
80 ; CHECK-NEXT: br label [[EXIT:%.*]]
82 ; CHECK-NEXT: br label [[EXIT]]
84 ; CHECK-NEXT: ret i32 [[V:%.*]]
86 br i1 %cond, label %A, label %B
92 %w = phi i32 [%v, %A], [undef, %B]
96 define i8 @undef_poison(i1 %cond) {
97 ; CHECK-LABEL: @undef_poison(
98 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
100 ; CHECK-NEXT: br label [[EXIT:%.*]]
102 ; CHECK-NEXT: br label [[EXIT]]
104 ; CHECK-NEXT: ret i8 undef
106 br i1 %cond, label %A, label %B
112 %r = phi i8 [undef, %A], [poison, %B]
116 define i8 @only_undef(i1 %cond) {
117 ; CHECK-LABEL: @only_undef(
118 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
120 ; CHECK-NEXT: br label [[EXIT:%.*]]
122 ; CHECK-NEXT: br label [[EXIT]]
124 ; CHECK-NEXT: ret i8 undef
126 br i1 %cond, label %A, label %B
132 %r = phi i8 [undef, %A], [undef, %B]
136 define i8 @only_poison(i1 %cond) {
137 ; CHECK-LABEL: @only_poison(
138 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
140 ; CHECK-NEXT: br label [[EXIT:%.*]]
142 ; CHECK-NEXT: br label [[EXIT]]
144 ; CHECK-NEXT: ret i8 undef
146 br i1 %cond, label %A, label %B
152 %r = phi i8 [poison, %A], [poison, %B]
156 ; Should not fold srem to -1 due to incorrect context instruction when
157 ; threading over phi.
158 define i32 @pr61312() {
159 ; CHECK-LABEL: @pr61312(
161 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
163 ; CHECK-NEXT: [[A_0:%.*]] = phi i32 [ 2, [[ENTRY:%.*]] ], [ [[DEC:%.*]], [[FOR_INC:%.*]] ]
164 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[A_0]], 0
165 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_INC]], label [[FOR_END:%.*]]
167 ; CHECK-NEXT: [[DEC]] = add nsw i32 [[A_0]], -1
168 ; CHECK-NEXT: br label [[FOR_COND]]
170 ; CHECK-NEXT: [[REM:%.*]] = srem i32 -1, [[A_0]]
171 ; CHECK-NEXT: ret i32 [[REM]]
177 %a.0 = phi i32 [ 2, %entry ], [ %dec, %for.inc ]
178 %cmp = icmp sge i32 %a.0, 0
179 br i1 %cmp, label %for.inc, label %for.end
182 %dec = add nsw i32 %a.0, -1
186 %rem = srem i32 -1, %a.0