Skip to content

[NFC][Sink] Change runtime checks to asserts #137354

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 3 commits into from
Apr 25, 2025
Merged
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
14 changes: 6 additions & 8 deletions llvm/lib/Transforms/Scalar/Sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ static bool IsAcceptableTarget(Instruction *Inst, BasicBlock *SuccToSinkTo,
!Inst->hasMetadata(LLVMContext::MD_invariant_load))
return false;

// We don't want to sink across a critical edge if we don't dominate the
// successor. We could be introducing calculations to new code paths.
if (!DT.dominates(Inst->getParent(), SuccToSinkTo))
return false;

// Don't sink instructions into a loop.
Loop *succ = LI.getLoopFor(SuccToSinkTo);
Loop *cur = LI.getLoopFor(Inst->getParent());
Expand Down Expand Up @@ -144,9 +139,6 @@ static bool SinkInstruction(Instruction *Inst,
SuccToSinkTo = DT.findNearestCommonDominator(SuccToSinkTo, UseBlock);
else
SuccToSinkTo = UseBlock;
// The current basic block needs to dominate the candidate.
if (!DT.dominates(BB, SuccToSinkTo))
return false;
}

if (SuccToSinkTo) {
Expand All @@ -167,6 +159,12 @@ static bool SinkInstruction(Instruction *Inst,
Inst->getParent()->printAsOperand(dbgs(), false); dbgs() << " -> ";
SuccToSinkTo->printAsOperand(dbgs(), false); dbgs() << ")\n");

// The current location of Inst dominates all uses, thus it must dominate
// SuccToSinkTo, which is on the IDom chain between the nearest common
// dominator to all uses and the current location.
assert(DT.dominates(BB, SuccToSinkTo) &&
"SuccToSinkTo must be dominated by current Inst location!");

// Move the instruction.
Inst->moveBefore(SuccToSinkTo->getFirstInsertionPt());
return true;
Expand Down
Loading