[llvm] 1a5666a - [SCEV] Defer loop property checks from ea12c2cb as late as possible
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 18 13:48:03 PST 2021
Author: Philip Reames
Date: 2021-11-18T13:47:45-08:00
New Revision: 1a5666acb281c7510504e726ba481d09ab5f5b95
URL: https://github.com/llvm/llvm-project/commit/1a5666acb281c7510504e726ba481d09ab5f5b95
DIFF: https://github.com/llvm/llvm-project/commit/1a5666acb281c7510504e726ba481d09ab5f5b95.diff
LOG: [SCEV] Defer loop property checks from ea12c2cb as late as possible
This is a speculative compile time optimization to address a reported regression. It's the only thing which vaguely makes sense.
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index f7c22cfb03100..adc4540bb2b7d 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8321,8 +8321,13 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L,
// the same values on self-wrap of the IV, then we can infer that IV
// doesn't self wrap because if it did, we'd have an infinite (undefined)
// loop.
- if (ControlsExit && isLoopInvariant(RHS, L) && loopHasNoAbnormalExits(L) &&
- loopIsFiniteByAssumption(L)) {
+ if (ControlsExit && isLoopInvariant(RHS, L)) {
+ auto deferredLoopProperties = [&]() {
+ // Conceptually, these two checks should be in the immediately guarding
+ // if clause, but we defer their actual execution to after the cheaper
+ // checks have all been done.
+ return loopHasNoAbnormalExits(L) && loopIsFiniteByAssumption(L);
+ };
// TODO: We can peel off any functions which are invertible *in L*. Loop
// invariant terms are effectively constants for our purposes here.
@@ -8332,7 +8337,8 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L,
if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(InnerLHS)) {
auto *StrideC = dyn_cast<SCEVConstant>(AR->getStepRecurrence(*this));
if (!AR->hasNoSelfWrap() && AR->getLoop() == L && AR->isAffine() &&
- StrideC && StrideC->getAPInt().isPowerOf2()) {
+ StrideC && StrideC->getAPInt().isPowerOf2() &&
+ deferredLoopProperties()) {
auto Flags = AR->getNoWrapFlags();
Flags = setFlags(Flags, SCEV::FlagNW);
SmallVector<const SCEV*> Operands{AR->operands()};
More information about the llvm-commits
mailing list