Skip to content

Commit 8ba650a

Browse files
committed
[InstCombine] Avoid self-replacing in getUndefReplacement
1 parent b3adfaf commit 8ba650a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5212,7 +5212,7 @@ Instruction *InstCombinerImpl::visitFreeze(FreezeInst &I) {
52125212
else if (match(U, m_Select(m_Specific(&I), m_Constant(), m_Value())))
52135213
V = ConstantInt::getTrue(Ty);
52145214
else if (match(U, m_c_Select(m_Specific(&I), m_Value(V)))) {
5215-
if (!isGuaranteedNotToBeUndefOrPoison(V, &AC, &I, &DT))
5215+
if (V == &I || !isGuaranteedNotToBeUndefOrPoison(V, &AC, &I, &DT))
52165216
V = NullValue;
52175217
} else if (auto *PHI = dyn_cast<PHINode>(U)) {
52185218
if (Value *MaybeV = pickCommonConstantFromPHI(*PHI))
@@ -5225,6 +5225,7 @@ Instruction *InstCombinerImpl::visitFreeze(FreezeInst &I) {
52255225
BestValue = NullValue;
52265226
}
52275227
assert(BestValue && "Must have at least one use");
5228+
assert(BestValue != &I && "Cannot replace with itself");
52285229
return BestValue;
52295230
};
52305231

llvm/test/Transforms/InstCombine/freeze.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ define ptr @freeze_ptrmask_nonnull(ptr %p, i64 noundef %m) {
14671467
define i64 @pr161492_1(i1 %cond) {
14681468
; CHECK-LABEL: define i64 @pr161492_1(
14691469
; CHECK-SAME: i1 [[COND:%.*]]) {
1470-
; CHECK-NEXT: ret i64 poison
1470+
; CHECK-NEXT: ret i64 0
14711471
;
14721472
%fr1 = freeze i64 poison
14731473
%fr2 = freeze i64 poison
@@ -1478,7 +1478,7 @@ define i64 @pr161492_1(i1 %cond) {
14781478
define i64 @pr161492_2(i1 %cond) {
14791479
; CHECK-LABEL: define i64 @pr161492_2(
14801480
; CHECK-SAME: i1 [[COND:%.*]]) {
1481-
; CHECK-NEXT: ret i64 poison
1481+
; CHECK-NEXT: ret i64 0
14821482
;
14831483
%fr = freeze i64 poison
14841484
%ret = select i1 %cond, i64 %fr, i64 %fr

0 commit comments

Comments
 (0)