Skip to content

Commit e5ad36c

Browse files
Review fix 2
Change-Id: I1e2f175cc22c3e0190f2e8f0ad8196a35e53af71
1 parent 0f5ed03 commit e5ad36c

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5180,7 +5180,7 @@ Instruction *InstCombinerImpl::visitFreeze(FreezeInst &I) {
51805180
// TODO: This could use getBinopAbsorber() / getBinopIdentity() to avoid
51815181
// duplicating logic for binops at least.
51825182
auto getUndefReplacement = [&](Type *Ty) {
5183-
auto pickCommonConstantFromPHI = [](PHINode &PN) -> Value * {
5183+
auto pickCommonConstantFromPHI = [&](PHINode &PN) -> Value * {
51845184
// phi(freeze(undef), C, C). Choose C for freeze so the PHI can be
51855185
// removed.
51865186
Constant *BestValue = nullptr;
@@ -5192,11 +5192,11 @@ Instruction *InstCombinerImpl::visitFreeze(FreezeInst &I) {
51925192
if (!isa<Constant>(V))
51935193
return nullptr;
51945194

5195-
C = cast<Constant>(V);
5196-
5197-
if (isa<UndefValue>(C) || isa<PoisonValue>(C))
5195+
if (!isGuaranteedNotToBeUndefOrPoison(V, &AC, &I, &DT))
51985196
return nullptr;
51995197

5198+
C = cast<Constant>(V);
5199+
52005200
if (BestValue && BestValue != C)
52015201
return nullptr;
52025202

llvm/test/Transforms/InstCombine/in-freeze-phi.ll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,23 @@ define i32 @multi_use_one_folds_one_not_zero(i1 %c0, i1 %c1, i1 %c2) {
151151
; CHECK-LABEL: define i32 @multi_use_one_folds_one_not_zero(
152152
; CHECK-SAME: i1 [[C0:%.*]], i1 [[C1:%.*]], i1 [[C2:%.*]]) {
153153
; CHECK-NEXT: [[ENTRY:.*:]]
154-
; CHECK-NEXT: br i1 [[C0]], label %[[BB_OTHER2:.*]], label %[[CC:.*]]
155-
; CHECK: [[BB_OTHER2]]:
154+
; CHECK-NEXT: br i1 [[C0]], label %[[BB_OTHER3:.*]], label %[[CC1:.*]]
155+
; CHECK: [[BB_OTHER3]]:
156156
; CHECK-NEXT: br label %[[MID:.*]]
157-
; CHECK: [[CC]]:
157+
; CHECK: [[CC1]]:
158158
; CHECK-NEXT: br i1 [[C1]], label %[[CA:.*]], label %[[CB:.*]]
159159
; CHECK: [[CA]]:
160160
; CHECK-NEXT: br label %[[MID]]
161161
; CHECK: [[CB]]:
162162
; CHECK-NEXT: br label %[[MID]]
163163
; CHECK: [[MID]]:
164-
; CHECK-NEXT: [[PHI_FOLD:%.*]] = phi i32 [ 0, %[[BB_OTHER2]] ], [ 1, %[[CA]] ], [ 1, %[[CB]] ]
164+
; CHECK-NEXT: [[PHI_FOLD:%.*]] = phi i32 [ 0, %[[BB_OTHER3]] ], [ 1, %[[CA]] ], [ 1, %[[CB]] ]
165165
; CHECK-NEXT: br i1 [[C2]], label %[[BB_FREEZE2:.*]], label %[[CD:.*]]
166166
; CHECK: [[BB_FREEZE2]]:
167167
; CHECK-NEXT: br label %[[FINAL:.*]]
168-
; CHECK: [[BB_OTHER3:.*:]]
168+
; CHECK: [[BB_OTHER2:.*:]]
169169
; CHECK-NEXT: br i1 true, label %[[CA]], label %[[CB]]
170-
; CHECK: [[CC1:.*:]]
170+
; CHECK: [[CC:.*:]]
171171
; CHECK-NEXT: br label %[[FINAL]]
172172
; CHECK: [[CD]]:
173173
; CHECK-NEXT: br label %[[FINAL]]
@@ -237,8 +237,8 @@ final:
237237
ret i32 %phi
238238
}
239239

240-
define i32 @phi_freeze_undef(i1 %c0, i1 %c1) {
241-
; CHECK-LABEL: define i32 @phi_freeze_undef(
240+
define <2 x i32> @phi_freeze_poison_vec(i1 %c0, i1 %c1) {
241+
; CHECK-LABEL: define <2 x i32> @phi_freeze_poison_vec(
242242
; CHECK-SAME: i1 [[C0:%.*]], i1 [[C1:%.*]]) {
243243
; CHECK-NEXT: [[ENTRY:.*:]]
244244
; CHECK-NEXT: br i1 [[C0]], label %[[BB_FREEZE:.*]], label %[[BB_OTHER:.*]]
@@ -251,13 +251,14 @@ define i32 @phi_freeze_undef(i1 %c0, i1 %c1) {
251251
; CHECK: [[CB]]:
252252
; CHECK-NEXT: br label %[[FINAL]]
253253
; CHECK: [[FINAL]]:
254-
; CHECK-NEXT: ret i32 0
254+
; CHECK-NEXT: [[PHI:%.*]] = phi <2 x i32> [ zeroinitializer, %[[BB_FREEZE]] ], [ <i32 poison, i32 1>, %[[CA]] ], [ <i32 poison, i32 1>, %[[CB]] ]
255+
; CHECK-NEXT: ret <2 x i32> [[PHI]]
255256
;
256257
entry:
257258
br i1 %c0, label %bb_freeze, label %bb_other
258259

259260
bb_freeze:
260-
%f = freeze i32 undef
261+
%f = freeze <2 x i32> undef
261262
br label %final
262263

263264
bb_other:
@@ -268,6 +269,6 @@ cB:
268269
br label %final
269270

270271
final:
271-
%phi = phi i32 [ %f, %bb_freeze ], [ undef, %cA ], [ undef, %cB ]
272-
ret i32 %phi
272+
%phi = phi <2 x i32> [ %f, %bb_freeze ], [ <i32 poison, i32 1>, %cA ], [ <i32 poison, i32 1>, %cB ]
273+
ret <2 x i32> %phi
273274
}

0 commit comments

Comments
 (0)