Skip to content

[ConstraintElim] Preserve analyses when IR is unchanged. #128588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,8 +1435,9 @@ static bool checkAndReplaceCondition(
generateReproducer(Cmp, ReproducerModule, ReproducerCondStack, Info, DT);
Constant *ConstantC = ConstantInt::getBool(
CmpInst::makeCmpResultType(Cmp->getType()), IsTrue);
Cmp->replaceUsesWithIf(ConstantC, [&DT, NumIn, NumOut,
ContextInst](Use &U) {
bool Changed = false;
Cmp->replaceUsesWithIf(ConstantC, [&DT, NumIn, NumOut, ContextInst,
&Changed](Use &U) {
auto *UserI = getContextInstForUse(U);
auto *DTN = DT.getNode(UserI->getParent());
if (!DTN || DTN->getDFSNumIn() < NumIn || DTN->getDFSNumOut() > NumOut)
Expand All @@ -1448,12 +1449,14 @@ static bool checkAndReplaceCondition(
// Conditions in an assume trivially simplify to true. Skip uses
// in assume calls to not destroy the available information.
auto *II = dyn_cast<IntrinsicInst>(U.getUser());
return !II || II->getIntrinsicID() != Intrinsic::assume;
bool ShouldReplace = !II || II->getIntrinsicID() != Intrinsic::assume;
Changed |= ShouldReplace;
return ShouldReplace;
});
NumCondsRemoved++;
if (Cmp->use_empty())
ToRemove.push_back(Cmp);
return true;
return Changed;
};

if (auto ImpliedCondition =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
; CHECK-NEXT: Running analysis: ScalarEvolutionAnalysis on test_mul_const_nuw_unsigned_14
; CHECK-NEXT: Running analysis: TargetLibraryAnalysis on test_mul_const_nuw_unsigned_14
; CHECK-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis on test_mul_const_nuw_unsigned_14
; CHECK-NEXT: Invalidating analysis: DemandedBitsAnalysis on test_mul_const_nuw_unsigned_14
; CHECK-NEXT: Running pass: RequireAnalysisPass
; CHECK-NEXT: Running analysis: DemandedBitsAnalysis on test_mul_const_nuw_unsigned_14


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

Expand Down