summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Trick <atrick@apple.com>2011-10-15 06:19:55 +0000
committerAndrew Trick <atrick@apple.com>2011-10-15 06:19:55 +0000
commit365c9f1ff55bef134c6b9707f7df44d680ddabea (patch)
treeedc2f1c2fa2fa67906158462fba8d4a8c96ccfab
parent569c4a4767428d7b489db1e634ced5a3b36d8a1d (diff)
downloadllvm-365c9f1ff55bef134c6b9707f7df44d680ddabea.tar.gz
llvm-365c9f1ff55bef134c6b9707f7df44d680ddabea.tar.bz2
llvm-365c9f1ff55bef134c6b9707f7df44d680ddabea.tar.xz
Fix SCEVExpander assert during LSR: "argument of incompatible type".
Just because we're dealing with a GEP doesn't mean we can assert the SCEV has a pointer type. The fix is simply to ignore the SCEV pointer type, which we really didn't need. Fixes PR11138 webkit crash. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142058 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Analysis/ScalarEvolutionExpander.h3
-rw-r--r--lib/Analysis/ScalarEvolutionExpander.cpp11
-rw-r--r--test/Transforms/LoopStrengthReduce/2011-10-14-IntPtr.ll27
3 files changed, 33 insertions, 8 deletions
diff --git a/include/llvm/Analysis/ScalarEvolutionExpander.h b/include/llvm/Analysis/ScalarEvolutionExpander.h
index 1080580c96..a4ad1451d4 100644
--- a/include/llvm/Analysis/ScalarEvolutionExpander.h
+++ b/include/llvm/Analysis/ScalarEvolutionExpander.h
@@ -237,8 +237,7 @@ namespace llvm {
bool isNormalAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L);
- bool isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L,
- Type *ExpandTy);
+ bool isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L);
Value *expandAddRecExprLiterally(const SCEVAddRecExpr *);
PHINode *getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
index e76b6b10cf..47f0f32116 100644
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -881,7 +881,7 @@ bool SCEVExpander::isNormalAddRecExprPHI(PHINode *PN, Instruction *IncV,
/// should match any patterns generated by getAddRecExprPHILiterally and
/// expandAddtoGEP.
bool SCEVExpander::isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV,
- const Loop *L, Type *ExpandTy) {
+ const Loop *L) {
switch (IncV->getOpcode()) {
// Check for a simple Add/Sub or GEP of a loop invariant step.
case Instruction::Add:
@@ -904,7 +904,7 @@ bool SCEVExpander::isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV,
// i1* is used by the expander to represent an address-size element.
if (IncV->getNumOperands() != 2)
return false;
- unsigned AS = cast<PointerType>(ExpandTy)->getAddressSpace();
+ unsigned AS = cast<PointerType>(IncV->getType())->getAddressSpace();
if (IncV->getType() != Type::getInt1PtrTy(SE.getContext(), AS)
&& IncV->getType() != Type::getInt8PtrTy(SE.getContext(), AS))
return false;
@@ -954,7 +954,7 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
cast<Instruction>(PN->getIncomingValueForBlock(LatchBlock));
if (LSRMode) {
- if (!isExpandedAddRecExprPHI(PN, IncV, L, ExpandTy))
+ if (!isExpandedAddRecExprPHI(PN, IncV, L))
continue;
}
else {
@@ -1547,9 +1547,8 @@ unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
cast<Instruction>(Phi->getIncomingValueForBlock(LatchBlock));
// If this phi is more canonical, swap it with the original.
- if (!isExpandedAddRecExprPHI(OrigPhiRef, OrigInc, L,
- OrigPhiRef->getType())
- && isExpandedAddRecExprPHI(Phi, IsomorphicInc, L, Phi->getType())) {
+ if (!isExpandedAddRecExprPHI(OrigPhiRef, OrigInc, L)
+ && isExpandedAddRecExprPHI(Phi, IsomorphicInc, L)) {
std::swap(OrigPhiRef, Phi);
std::swap(OrigInc, IsomorphicInc);
}
diff --git a/test/Transforms/LoopStrengthReduce/2011-10-14-IntPtr.ll b/test/Transforms/LoopStrengthReduce/2011-10-14-IntPtr.ll
new file mode 100644
index 0000000000..60cc7a5163
--- /dev/null
+++ b/test/Transforms/LoopStrengthReduce/2011-10-14-IntPtr.ll
@@ -0,0 +1,27 @@
+; RUN: opt -loop-reduce -S < %s | FileCheck %s
+;
+; Test SCEVExpander reusing a phi->gep->phi IV when SCEV "wrongly"
+; reports the expression as an IntegerTy.
+
+target triple = "x86_64-apple-darwin"
+
+; CHECK: @test
+; CHECK: phi
+; CHECK-NOT: phi
+define void @test(i32 %rowStride) ssp align 2 {
+entry:
+ %cond = select i1 undef, i32 %rowStride, i32 4
+ br label %for.end
+
+for.end.critedge: ; preds = %for.end
+ br label %for.end
+
+for.end: ; preds = %for.end.critedge, %entry
+ br i1 undef, label %for.body83, label %for.end.critedge
+
+for.body83: ; preds = %for.body83, %for.end
+ %ptr.0157 = phi i8* [ %add.ptr96, %for.body83 ], [ null, %for.end ]
+ store i8 undef, i8* %ptr.0157, align 1
+ %add.ptr96 = getelementptr inbounds i8* %ptr.0157, i32 %cond
+ br label %for.body83
+}