aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2010-09-14 20:57:16 +0000
committerBill Wendling <isanbard@gmail.com>2010-09-14 20:57:16 +0000
commit02bf305a3f5879eddcb4bd1f3917e021349fc0c0 (patch)
tree03e7439a09990043bd9ca2e9d07d0cf2444704f2
parent732d1a4c8fad859775572b07ec2fbc4812d98fd8 (diff)
Approved by Chris:
$ svn merge -c 113057 https://llvm.org/svn/llvm-project/llvm/trunk --- Merging r113057 into '.': A test/Transforms/LoopSimplify/preserve-scev.ll U lib/Transforms/Utils/LoopSimplify.cpp git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_28@113851 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Utils/LoopSimplify.cpp11
-rw-r--r--test/Transforms/LoopSimplify/preserve-scev.ll50
2 files changed, 60 insertions, 1 deletions
diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp
index 2f0a175d5c..b3c4801a4f 100644
--- a/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/lib/Transforms/Utils/LoopSimplify.cpp
@@ -46,6 +46,7 @@
#include "llvm/LLVMContext.h"
#include "llvm/Type.h"
#include "llvm/Analysis/AliasAnalysis.h"
+#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -71,6 +72,7 @@ namespace {
AliasAnalysis *AA;
LoopInfo *LI;
DominatorTree *DT;
+ ScalarEvolution *SE;
Loop *L;
virtual bool runOnLoop(Loop *L, LPPassManager &LPM);
@@ -83,7 +85,7 @@ namespace {
AU.addPreserved<LoopInfo>();
AU.addPreserved<AliasAnalysis>();
- AU.addPreserved("scalar-evolution");
+ AU.addPreserved<ScalarEvolution>();
AU.addPreservedID(BreakCriticalEdgesID); // No critical edges added.
AU.addPreserved<DominanceFrontier>();
AU.addPreservedID(LCSSAID);
@@ -121,6 +123,7 @@ bool LoopSimplify::runOnLoop(Loop *l, LPPassManager &LPM) {
LI = &getAnalysis<LoopInfo>();
AA = getAnalysisIfAvailable<AliasAnalysis>();
DT = &getAnalysis<DominatorTree>();
+ SE = getAnalysisIfAvailable<ScalarEvolution>();
Changed |= ProcessLoop(L, LPM);
@@ -532,6 +535,12 @@ Loop *LoopSimplify::SeparateNestedLoop(Loop *L, LPPassManager &LPM) {
DEBUG(dbgs() << "LoopSimplify: Splitting out a new outer loop\n");
+ // If ScalarEvolution is around and knows anything about values in
+ // this loop, tell it to forget them, because we're about to
+ // substantially change it.
+ if (SE)
+ SE->forgetLoop(L);
+
BasicBlock *Header = L->getHeader();
BasicBlock *NewBB = SplitBlockPredecessors(Header, &OuterLoopPreds[0],
OuterLoopPreds.size(),
diff --git a/test/Transforms/LoopSimplify/preserve-scev.ll b/test/Transforms/LoopSimplify/preserve-scev.ll
new file mode 100644
index 0000000000..017a0d2108
--- /dev/null
+++ b/test/Transforms/LoopSimplify/preserve-scev.ll
@@ -0,0 +1,50 @@
+; RUN: opt -S < %s -indvars | opt -analyze -iv-users | grep {%cmp = icmp slt i32} | grep {= \{%\\.ph,+,1\}<%for.cond>}
+; PR8079
+
+; LoopSimplify should invalidate indvars when splitting out the
+; inner loop.
+
+@maxStat = external global i32
+
+define i32 @test() nounwind {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %if.then5, %if.end, %entry
+ %cuts.1 = phi i32 [ 0, %entry ], [ %inc, %if.then5 ], [ %cuts.1, %if.end ]
+ %0 = phi i32 [ 0, %entry ], [ %add, %if.end ], [ %add, %if.then5 ]
+ %add = add i32 %0, 1
+ %cmp = icmp slt i32 %0, 1
+ %tmp1 = load i32* @maxStat, align 4
+ br i1 %cmp, label %for.body, label %for.cond14.preheader
+
+for.cond14.preheader: ; preds = %for.cond
+ %cmp1726 = icmp sgt i32 %tmp1, 0
+ br i1 %cmp1726, label %for.body18, label %return
+
+for.body: ; preds = %for.cond
+ %cmp2 = icmp sgt i32 %tmp1, 100
+ br i1 %cmp2, label %return, label %if.end
+
+if.end: ; preds = %for.body
+ %cmp4 = icmp sgt i32 %tmp1, -1
+ br i1 %cmp4, label %if.then5, label %for.cond
+
+if.then5: ; preds = %if.end
+ call void @foo() nounwind
+ %inc = add i32 %cuts.1, 1
+ br label %for.cond
+
+for.body18: ; preds = %for.body18, %for.cond14.preheader
+ %i13.027 = phi i32 [ %1, %for.body18 ], [ 0, %for.cond14.preheader ]
+ call void @foo() nounwind
+ %1 = add nsw i32 %i13.027, 1
+ %tmp16 = load i32* @maxStat, align 4
+ %cmp17 = icmp slt i32 %1, %tmp16
+ br i1 %cmp17, label %for.body18, label %return
+
+return: ; preds = %for.body18, %for.body, %for.cond14.preheader
+ ret i32 0
+}
+
+declare void @foo() nounwind