Skip to content
Merged
Changes from 1 commit
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
16 changes: 9 additions & 7 deletions llvm/lib/Transforms/Scalar/Sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ 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;
// 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(Inst->getParent(), SuccToSinkTo) &&
"SuccToSinkTo must be dominated by current Inst location!");

// Don't sink instructions into a loop.
Loop *succ = LI.getLoopFor(SuccToSinkTo);
Expand Down Expand Up @@ -144,9 +145,10 @@ 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;
// The current basic block dominates all uses, thus it must dominate
// SuccToSinkTo, the nearest common dominator of all uses.
assert(DT.dominates(BB, SuccToSinkTo) &&
"SuccToSinkTo must be dominated by current basic block!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to replace the two asserts with a single one at the end of this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced the two asserts with one assert, but I've put the assert at the beginning of the function since it is already true at that point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I suggest to put it at the end is that SuccToSinkTo is changed in the function. So we are asserting that the property still holds after these adjustments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved assert to when SuccToSinkTo is used to sink instruction.

}

if (SuccToSinkTo) {
Expand Down
Loading