Skip to content

Commit 4b29c28

Browse files
authored
[ConstraintElim] Preserve analyses when IR is unchanged. (#128588)
1 parent e47cd46 commit 4b29c28

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,9 @@ static bool checkAndReplaceCondition(
14351435
generateReproducer(Cmp, ReproducerModule, ReproducerCondStack, Info, DT);
14361436
Constant *ConstantC = ConstantInt::getBool(
14371437
CmpInst::makeCmpResultType(Cmp->getType()), IsTrue);
1438-
Cmp->replaceUsesWithIf(ConstantC, [&DT, NumIn, NumOut,
1439-
ContextInst](Use &U) {
1438+
bool Changed = false;
1439+
Cmp->replaceUsesWithIf(ConstantC, [&DT, NumIn, NumOut, ContextInst,
1440+
&Changed](Use &U) {
14401441
auto *UserI = getContextInstForUse(U);
14411442
auto *DTN = DT.getNode(UserI->getParent());
14421443
if (!DTN || DTN->getDFSNumIn() < NumIn || DTN->getDFSNumOut() > NumOut)
@@ -1448,12 +1449,14 @@ static bool checkAndReplaceCondition(
14481449
// Conditions in an assume trivially simplify to true. Skip uses
14491450
// in assume calls to not destroy the available information.
14501451
auto *II = dyn_cast<IntrinsicInst>(U.getUser());
1451-
return !II || II->getIntrinsicID() != Intrinsic::assume;
1452+
bool ShouldReplace = !II || II->getIntrinsicID() != Intrinsic::assume;
1453+
Changed |= ShouldReplace;
1454+
return ShouldReplace;
14521455
});
14531456
NumCondsRemoved++;
14541457
if (Cmp->use_empty())
14551458
ToRemove.push_back(Cmp);
1456-
return true;
1459+
return Changed;
14571460
};
14581461

14591462
if (auto ImpliedCondition =

llvm/test/Transforms/ConstraintElimination/analysis-invalidation.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
; CHECK-NEXT: Running analysis: ScalarEvolutionAnalysis on test_mul_const_nuw_unsigned_14
4444
; CHECK-NEXT: Running analysis: TargetLibraryAnalysis on test_mul_const_nuw_unsigned_14
4545
; CHECK-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis on test_mul_const_nuw_unsigned_14
46-
; CHECK-NEXT: Invalidating analysis: DemandedBitsAnalysis on test_mul_const_nuw_unsigned_14
47-
; CHECK-NEXT: Running pass: RequireAnalysisPass
48-
; CHECK-NEXT: Running analysis: DemandedBitsAnalysis on test_mul_const_nuw_unsigned_14
49-
5046

5147
declare { i8, i1 } @llvm.ssub.with.overflow.i8(i8, i8)
5248

0 commit comments

Comments
 (0)