[llvm] f9d4e7e - [NFC][Sink] Change runtime checks to asserts (#137354)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 25 14:21:15 PDT 2025
Author: LU-JOHN
Date: 2025-04-25T23:21:11+02:00
New Revision: f9d4e7ef8b656952d3abcc4c5b2634bbf4cb93fe
URL: https://github.com/llvm/llvm-project/commit/f9d4e7ef8b656952d3abcc4c5b2634bbf4cb93fe
DIFF: https://github.com/llvm/llvm-project/commit/f9d4e7ef8b656952d3abcc4c5b2634bbf4cb93fe.diff
LOG: [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 <John.Lu at amd.com>
Added:
Modified:
llvm/lib/Transforms/Scalar/Sink.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/Sink.cpp b/llvm/lib/Transforms/Scalar/Sink.cpp
index 1a48a59c4189e..4b63698e5e132 100644
--- a/llvm/lib/Transforms/Scalar/Sink.cpp
+++ b/llvm/lib/Transforms/Scalar/Sink.cpp
@@ -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());
@@ -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) {
@@ -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;
More information about the llvm-commits
mailing list