Skip to content

Commit ceb0237

Browse files
authored
[LoopVectorize] Improve algorithm for hoisting runtime checks (#73515)
When attempting to hoist runtime checks out of a loop we currently avoid creating pointer diff checks and prefer to do expanded range checks instead. This gives us the opportunity to hoist runtime checks out of a loop, since these checks are loop invariant. However, in some cases the pointer diff checks would also be loop invariant and so will naturally get hoisted. Therefore, since diff checks are cheaper so we should prefer to use those instead.
1 parent 777b6de commit ceb0237

File tree

2 files changed

+124
-27
lines changed

2 files changed

+124
-27
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,12 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
347347
auto *SinkStartAR = cast<SCEVAddRecExpr>(SinkStartInt);
348348
const Loop *StartARLoop = SrcStartAR->getLoop();
349349
if (StartARLoop == SinkStartAR->getLoop() &&
350-
StartARLoop == InnerLoop->getParentLoop()) {
350+
StartARLoop == InnerLoop->getParentLoop() &&
351+
// If the diff check would already be loop invariant (due to the
352+
// recurrences being the same), then we prefer to keep the diff checks
353+
// because they are cheaper.
354+
SrcStartAR->getStepRecurrence(*SE) !=
355+
SinkStartAR->getStepRecurrence(*SE)) {
351356
LLVM_DEBUG(dbgs() << "LAA: Not creating diff runtime check, since these "
352357
"cannot be hoisted out of the outer loop\n");
353358
CanUseDiffCheck = false;

0 commit comments

Comments
 (0)