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: [[W:%.*]] = phi i32 [ [[V:%.*]], [[A]] ], [ undef, [[B]] ]
85 ; CHECK-NEXT: ret i32 [[W]]
87 br i1 %cond, label %A, label %B
93 %w = phi i32 [%v, %A], [undef, %B]
97 define i8 @undef_poison(i1 %cond) {
98 ; CHECK-LABEL: @undef_poison(
99 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
101 ; CHECK-NEXT: br label [[EXIT:%.*]]
103 ; CHECK-NEXT: br label [[EXIT]]
105 ; CHECK-NEXT: ret i8 undef
107 br i1 %cond, label %A, label %B
113 %r = phi i8 [undef, %A], [poison, %B]
117 define i8 @only_undef(i1 %cond) {
118 ; CHECK-LABEL: @only_undef(
119 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
121 ; CHECK-NEXT: br label [[EXIT:%.*]]
123 ; CHECK-NEXT: br label [[EXIT]]
125 ; CHECK-NEXT: ret i8 undef
127 br i1 %cond, label %A, label %B
133 %r = phi i8 [undef, %A], [undef, %B]
137 define i8 @only_poison(i1 %cond) {
138 ; CHECK-LABEL: @only_poison(
139 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
141 ; CHECK-NEXT: br label [[EXIT:%.*]]
143 ; CHECK-NEXT: br label [[EXIT]]
145 ; CHECK-NEXT: ret i8 poison
147 br i1 %cond, label %A, label %B
153 %r = phi i8 [poison, %A], [poison, %B]
157 ; Should not fold srem to -1 due to incorrect context instruction when
158 ; threading over phi.
159 define i32 @pr61312() {
160 ; CHECK-LABEL: @pr61312(
162 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
164 ; CHECK-NEXT: [[A_0:%.*]] = phi i32 [ 2, [[ENTRY:%.*]] ], [ [[DEC:%.*]], [[FOR_INC:%.*]] ]
165 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[A_0]], 0
166 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_INC]], label [[FOR_END:%.*]]
168 ; CHECK-NEXT: [[DEC]] = add nsw i32 [[A_0]], -1
169 ; CHECK-NEXT: br label [[FOR_COND]]
171 ; CHECK-NEXT: [[REM:%.*]] = srem i32 -1, [[A_0]]
172 ; CHECK-NEXT: ret i32 [[REM]]
178 %a.0 = phi i32 [ 2, %entry ], [ %dec, %for.inc ]
179 %cmp = icmp sge i32 %a.0, 0
180 br i1 %cmp, label %for.inc, label %for.end
183 %dec = add nsw i32 %a.0, -1
187 %rem = srem i32 -1, %a.0