Skip to content

Commit f9d4e7e

Browse files
authored
[NFC][Sink] Change runtime checks to asserts (#137354)
Candidate block for sinking must be dominated by current location. This is true based on how the candidate block was selected. Runtime checks are not necessary and has been changed to an assertion. --------- Signed-off-by: John Lu <[email protected]>
1 parent bd96fa7 commit f9d4e7e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

llvm/lib/Transforms/Scalar/Sink.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ 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;
89-
9085
// Don't sink instructions into a loop.
9186
Loop *succ = LI.getLoopFor(SuccToSinkTo);
9287
Loop *cur = LI.getLoopFor(Inst->getParent());
@@ -144,9 +139,6 @@ static bool SinkInstruction(Instruction *Inst,
144139
SuccToSinkTo = DT.findNearestCommonDominator(SuccToSinkTo, UseBlock);
145140
else
146141
SuccToSinkTo = UseBlock;
147-
// The current basic block needs to dominate the candidate.
148-
if (!DT.dominates(BB, SuccToSinkTo))
149-
return false;
150142
}
151143

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

162+
// The current location of Inst dominates all uses, thus it must dominate
163+
// SuccToSinkTo, which is on the IDom chain between the nearest common
164+
// dominator to all uses and the current location.
165+
assert(DT.dominates(BB, SuccToSinkTo) &&
166+
"SuccToSinkTo must be dominated by current Inst location!");
167+
170168
// Move the instruction.
171169
Inst->moveBefore(SuccToSinkTo->getFirstInsertionPt());
172170
return true;

0 commit comments

Comments
 (0)