Skip to content

Commit d6914fb

Browse files
committed
Change dynamic checks to asserts
Signed-off-by: John Lu <[email protected]>
1 parent 82f1f5e commit d6914fb

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

llvm/lib/Transforms/Scalar/Sink.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ static bool IsAcceptableTarget(Instruction *Inst, BasicBlock *SuccToSinkTo,
8282
!Inst->hasMetadata(LLVMContext::MD_invariant_load))
8383
return false;
8484

85-
// We don't want to sink across a critical edge if we don't dominate the
86-
// successor. We could be introducing calculations to new code paths.
87-
if (!DT.dominates(Inst->getParent(), SuccToSinkTo))
88-
return false;
85+
// The current location of Inst dominates all uses, thus it must dominate
86+
// SuccToSinkTo, which is on the IDom chain between the nearest common
87+
// dominator to all uses and the current location.
88+
assert(DT.dominates(Inst->getParent(), SuccToSinkTo) &&
89+
"SuccToSinkTo must be dominated by current Inst location!");
8990

9091
// Don't sink instructions into a loop.
9192
Loop *succ = LI.getLoopFor(SuccToSinkTo);
@@ -144,9 +145,10 @@ static bool SinkInstruction(Instruction *Inst,
144145
SuccToSinkTo = DT.findNearestCommonDominator(SuccToSinkTo, UseBlock);
145146
else
146147
SuccToSinkTo = UseBlock;
147-
// The current basic block needs to dominate the candidate.
148-
if (!DT.dominates(BB, SuccToSinkTo))
149-
return false;
148+
// The current basic block dominates all uses, thus it must dominate
149+
// SuccToSinkTo, the nearest common dominator of all uses.
150+
assert(DT.dominates(BB, SuccToSinkTo) &&
151+
"SuccToSinkTo must be dominated by current basic block!");
150152
}
151153

152154
if (SuccToSinkTo) {

0 commit comments

Comments
 (0)