summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Trick <atrick@apple.com>2012-01-20 21:23:40 +0000
committerAndrew Trick <atrick@apple.com>2012-01-20 21:23:40 +0000
commit0041d4d447c26825e566ba38a4fe301471fda1eb (patch)
treee58e18bc89fc519d44827fd990234a899aee07ff
parenta44919ef4574621a64817dfb85cbf68ee4ebf7a8 (diff)
downloadllvm-0041d4d447c26825e566ba38a4fe301471fda1eb.tar.gz
llvm-0041d4d447c26825e566ba38a4fe301471fda1eb.tar.bz2
llvm-0041d4d447c26825e566ba38a4fe301471fda1eb.tar.xz
Handle a corner case with IV chain collection with bailout instead of assert.
Fixes PR11783: bad cast to AddRecExpr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148572 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp8
-rw-r--r--test/Transforms/LoopStrengthReduce/ivchain.ll43
2 files changed, 49 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 42f45ae627..5aee483332 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -2484,11 +2484,15 @@ void LSRInstance::ChainInstruction(Instruction *UserInst, Instruction *IVOper,
DEBUG(dbgs() << "IV Chain Limit\n");
return;
}
+ LastIncExpr = SE.getSCEV(NextIV);
+ // IVUsers may have skipped over sign/zero extensions. We don't currently
+ // attempt to form chains involving extensions unless they can be hoisted
+ // into this loop's AddRec.
+ if (!isa<SCEVAddRecExpr>(LastIncExpr))
+ return;
++NChains;
IVChainVec.resize(NChains);
ChainUsersVec.resize(NChains);
- LastIncExpr = SE.getSCEV(NextIV);
- assert(isa<SCEVAddRecExpr>(LastIncExpr) && "expect recurrence at IV user");
DEBUG(dbgs() << "IV Head: (" << *UserInst << ") IV=" << *LastIncExpr
<< "\n");
}
diff --git a/test/Transforms/LoopStrengthReduce/ivchain.ll b/test/Transforms/LoopStrengthReduce/ivchain.ll
new file mode 100644
index 0000000000..ce7ad198de
--- /dev/null
+++ b/test/Transforms/LoopStrengthReduce/ivchain.ll
@@ -0,0 +1,43 @@
+; RUN: opt < %s -loop-reduce -S | FileCheck %s
+;
+; PR11782: bad cast to AddRecExpr.
+; A sign extend feeds an IVUser and cannot be hoisted into the AddRec.
+; CollectIVChains should bailout on this case.
+
+%struct = type { i8*, i8*, i16, i64, i16, i16, i16, i64, i64, i16, i8*, i64, i64, i64 }
+
+; CHECK: @test
+; CHECK: for.body:
+; CHECK: lsr.iv = phi %struct
+; CHECK: br
+define i32 @test(i8* %h, i32 %more) nounwind uwtable {
+entry:
+ br i1 undef, label %land.end238, label %return
+
+land.end238: ; preds = %if.end229
+ br label %for.body
+
+for.body: ; preds = %sw.epilog, %land.end238
+ %fbh.0 = phi %struct* [ undef, %land.end238 ], [ %incdec.ptr, %sw.epilog ]
+ %column_n.0 = phi i16 [ 0, %land.end238 ], [ %inc601, %sw.epilog ]
+ %conv250 = sext i16 %column_n.0 to i32
+ %add257 = add nsw i32 %conv250, 1
+ %conv258 = trunc i32 %add257 to i16
+ %cmp263 = icmp ult i16 undef, 2
+ br label %if.end388
+
+if.end388: ; preds = %if.then380, %if.else356
+ %ColLength = getelementptr inbounds %struct* %fbh.0, i64 0, i32 7
+ %call405 = call signext i16 @SQLColAttribute(i8* undef, i16 zeroext %conv258, i16 zeroext 1003, i8* null, i16 signext 0, i16* null, i64* %ColLength) nounwind
+ br label %sw.epilog
+
+sw.epilog: ; preds = %sw.bb542, %sw.bb523, %if.end475
+ %inc601 = add i16 %column_n.0, 1
+ %incdec.ptr = getelementptr inbounds %struct* %fbh.0, i64 1
+ br label %for.body
+
+return: ; preds = %entry
+ ret i32 1
+}
+
+declare signext i16 @SQLColAttribute(i8*, i16 zeroext, i16 zeroext, i8*, i16 signext, i16*, i64*)