Skip to content

Commit df49eed

Browse files
committed
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 llvm-svn: 113851
1 parent 19cad46 commit df49eed

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

llvm/lib/Transforms/Utils/LoopSimplify.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "llvm/LLVMContext.h"
4747
#include "llvm/Type.h"
4848
#include "llvm/Analysis/AliasAnalysis.h"
49+
#include "llvm/Analysis/ScalarEvolution.h"
4950
#include "llvm/Analysis/Dominators.h"
5051
#include "llvm/Analysis/LoopPass.h"
5152
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -71,6 +72,7 @@ namespace {
7172
AliasAnalysis *AA;
7273
LoopInfo *LI;
7374
DominatorTree *DT;
75+
ScalarEvolution *SE;
7476
Loop *L;
7577
virtual bool runOnLoop(Loop *L, LPPassManager &LPM);
7678

@@ -83,7 +85,7 @@ namespace {
8385
AU.addPreserved<LoopInfo>();
8486

8587
AU.addPreserved<AliasAnalysis>();
86-
AU.addPreserved("scalar-evolution");
88+
AU.addPreserved<ScalarEvolution>();
8789
AU.addPreservedID(BreakCriticalEdgesID); // No critical edges added.
8890
AU.addPreserved<DominanceFrontier>();
8991
AU.addPreservedID(LCSSAID);
@@ -121,6 +123,7 @@ bool LoopSimplify::runOnLoop(Loop *l, LPPassManager &LPM) {
121123
LI = &getAnalysis<LoopInfo>();
122124
AA = getAnalysisIfAvailable<AliasAnalysis>();
123125
DT = &getAnalysis<DominatorTree>();
126+
SE = getAnalysisIfAvailable<ScalarEvolution>();
124127

125128
Changed |= ProcessLoop(L, LPM);
126129

@@ -532,6 +535,12 @@ Loop *LoopSimplify::SeparateNestedLoop(Loop *L, LPPassManager &LPM) {
532535

533536
DEBUG(dbgs() << "LoopSimplify: Splitting out a new outer loop\n");
534537

538+
// If ScalarEvolution is around and knows anything about values in
539+
// this loop, tell it to forget them, because we're about to
540+
// substantially change it.
541+
if (SE)
542+
SE->forgetLoop(L);
543+
535544
BasicBlock *Header = L->getHeader();
536545
BasicBlock *NewBB = SplitBlockPredecessors(Header, &OuterLoopPreds[0],
537546
OuterLoopPreds.size(),
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; RUN: opt -S < %s -indvars | opt -analyze -iv-users | grep {%cmp = icmp slt i32} | grep {= \{%\\.ph,+,1\}<%for.cond>}
2+
; PR8079
3+
4+
; LoopSimplify should invalidate indvars when splitting out the
5+
; inner loop.
6+
7+
@maxStat = external global i32
8+
9+
define i32 @test() nounwind {
10+
entry:
11+
br label %for.cond
12+
13+
for.cond: ; preds = %if.then5, %if.end, %entry
14+
%cuts.1 = phi i32 [ 0, %entry ], [ %inc, %if.then5 ], [ %cuts.1, %if.end ]
15+
%0 = phi i32 [ 0, %entry ], [ %add, %if.end ], [ %add, %if.then5 ]
16+
%add = add i32 %0, 1
17+
%cmp = icmp slt i32 %0, 1
18+
%tmp1 = load i32* @maxStat, align 4
19+
br i1 %cmp, label %for.body, label %for.cond14.preheader
20+
21+
for.cond14.preheader: ; preds = %for.cond
22+
%cmp1726 = icmp sgt i32 %tmp1, 0
23+
br i1 %cmp1726, label %for.body18, label %return
24+
25+
for.body: ; preds = %for.cond
26+
%cmp2 = icmp sgt i32 %tmp1, 100
27+
br i1 %cmp2, label %return, label %if.end
28+
29+
if.end: ; preds = %for.body
30+
%cmp4 = icmp sgt i32 %tmp1, -1
31+
br i1 %cmp4, label %if.then5, label %for.cond
32+
33+
if.then5: ; preds = %if.end
34+
call void @foo() nounwind
35+
%inc = add i32 %cuts.1, 1
36+
br label %for.cond
37+
38+
for.body18: ; preds = %for.body18, %for.cond14.preheader
39+
%i13.027 = phi i32 [ %1, %for.body18 ], [ 0, %for.cond14.preheader ]
40+
call void @foo() nounwind
41+
%1 = add nsw i32 %i13.027, 1
42+
%tmp16 = load i32* @maxStat, align 4
43+
%cmp17 = icmp slt i32 %1, %tmp16
44+
br i1 %cmp17, label %for.body18, label %return
45+
46+
return: ; preds = %for.body18, %for.body, %for.cond14.preheader
47+
ret i32 0
48+
}
49+
50+
declare void @foo() nounwind

0 commit comments

Comments
 (0)