aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kazantsev <mkazantsev@azul.com>2020-11-26 13:20:02 +0700
committerMax Kazantsev <mkazantsev@azul.com>2020-11-26 13:20:02 +0700
commit14f2ad0e3cc54d5eb254b545a469e8ffdb62b119 (patch)
tree4832ed3ba5969bec1330f7d929d53a264fd40f38
parent2254e014a9019bf17c3f5cb27c1dc40ca0f2ffce (diff)
downloadllvm-14f2ad0e3cc54d5eb254b545a469e8ffdb62b119.zip
llvm-14f2ad0e3cc54d5eb254b545a469e8ffdb62b119.tar.gz
llvm-14f2ad0e3cc54d5eb254b545a469e8ffdb62b119.tar.bz2
[SCEV] Use isKnownPredicateAt in isLoopBackedgeGuardedByCond
A piece of code in `isLoopBackedgeGuardedByCond` basically duplicates the dominators traversal from `isBlockEntryGuardedByCond` called from `isKnownPredicateAt`, but it's less powerful because it does not give context to `isImpliedCond`. This patch reuses the `isKnownPredicateAt `function there, reducing the amount of code duplication and making it more powerful. Differential Revision: https://reviews.llvm.org/D92152 Reviewed By: skatkov
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp37
-rw-r--r--llvm/test/Transforms/LoopStrengthReduce/post-inc-icmpzero.ll2
2 files changed, 2 insertions, 37 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 53fd668..31b88c9 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -9911,42 +9911,7 @@ ScalarEvolution::isLoopBackedgeGuardedByCond(const Loop *L,
if (isImpliedViaGuard(Latch, Pred, LHS, RHS))
return true;
- for (DomTreeNode *DTN = DT[Latch], *HeaderDTN = DT[L->getHeader()];
- DTN != HeaderDTN; DTN = DTN->getIDom()) {
- assert(DTN && "should reach the loop header before reaching the root!");
-
- BasicBlock *BB = DTN->getBlock();
- if (isImpliedViaGuard(BB, Pred, LHS, RHS))
- return true;
-
- BasicBlock *PBB = BB->getSinglePredecessor();
- if (!PBB)
- continue;
-
- BranchInst *ContinuePredicate = dyn_cast<BranchInst>(PBB->getTerminator());
- if (!ContinuePredicate || !ContinuePredicate->isConditional())
- continue;
-
- Value *Condition = ContinuePredicate->getCondition();
-
- // If we have an edge `E` within the loop body that dominates the only
- // latch, the condition guarding `E` also guards the backedge. This
- // reasoning works only for loops with a single latch.
-
- BasicBlockEdge DominatingEdge(PBB, BB);
- if (DominatingEdge.isSingleEdge()) {
- // We're constructively (and conservatively) enumerating edges within the
- // loop body that dominate the latch. The dominator tree better agree
- // with us on this:
- assert(DT.dominates(DominatingEdge, Latch) && "should be!");
-
- if (isImpliedCond(Pred, LHS, RHS, Condition,
- BB != ContinuePredicate->getSuccessor(0)))
- return true;
- }
- }
-
- return false;
+ return isKnownPredicateAt(Pred, LHS, RHS, Latch->getTerminator());
}
bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB,
diff --git a/llvm/test/Transforms/LoopStrengthReduce/post-inc-icmpzero.ll b/llvm/test/Transforms/LoopStrengthReduce/post-inc-icmpzero.ll
index 8a07a49..c398289 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/post-inc-icmpzero.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/post-inc-icmpzero.ll
@@ -69,7 +69,7 @@ define void @_Z15IntegerToStringjjR7Vector2(i32 %i, i32 %radix, %struct.Vector2*
; CHECK-NEXT: [[UGLYGEP2:%.*]] = bitcast i8* [[UGLYGEP]] to i16*
; CHECK-NEXT: [[TMP29:%.*]] = load i16, i16* [[LSR_IV810]], align 2
; CHECK-NEXT: store i16 [[TMP29]], i16* [[UGLYGEP2]], align 2
-; CHECK-NEXT: [[LSR_IV_NEXT]] = add i64 [[LSR_IV]], 2
+; CHECK-NEXT: [[LSR_IV_NEXT]] = add nuw nsw i64 [[LSR_IV]], 2
; CHECK-NEXT: [[LSR_IV_NEXT3:%.*]] = inttoptr i64 [[LSR_IV_NEXT]] to i16*
; CHECK-NEXT: [[SCEVGEP9:%.*]] = getelementptr [33 x i16], [33 x i16]* [[LSR_IV8]], i64 0, i64 1
; CHECK-NEXT: [[TMP3]] = bitcast i16* [[SCEVGEP9]] to [33 x i16]*