summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2012-05-02 09:59:45 +0000
committerBill Wendling <isanbard@gmail.com>2012-05-02 09:59:45 +0000
commit55e7098bbc363473c01229517097d2a04e04e9b0 (patch)
treec3b240028b5376b8032808b7a52d237f0175c72e
parent0a552d611efe9d1070aff1d35c7f169dd1ab0be7 (diff)
downloadllvm-55e7098bbc363473c01229517097d2a04e04e9b0.tar.gz
llvm-55e7098bbc363473c01229517097d2a04e04e9b0.tar.bz2
llvm-55e7098bbc363473c01229517097d2a04e04e9b0.tar.xz
The value held in the vector may be RAUW'ed by some of the canonicalization
methods. Use a weak value handle to keep up with this. PR12245 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155984 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp5
-rw-r--r--test/Transforms/Reassociate/pr12245.ll50
2 files changed, 53 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp
index c4079e37a1..a37cb7c581 100644
--- a/lib/Transforms/Scalar/Reassociate.cpp
+++ b/lib/Transforms/Scalar/Reassociate.cpp
@@ -605,7 +605,8 @@ static unsigned FindInOperandList(SmallVectorImpl<ValueEntry> &Ops, unsigned i,
/// EmitAddTreeOfValues - Emit a tree of add instructions, summing Ops together
/// and returning the result. Insert the tree before I.
-static Value *EmitAddTreeOfValues(Instruction *I, SmallVectorImpl<Value*> &Ops){
+static Value *EmitAddTreeOfValues(Instruction *I,
+ SmallVectorImpl<WeakVH> &Ops){
if (Ops.size() == 1) return Ops.back();
Value *V1 = Ops.back();
@@ -879,7 +880,7 @@ Value *Reassociate::OptimizeAdd(Instruction *I,
// from an expression will drop a use of maxocc, and this can cause
// RemoveFactorFromExpression on successive values to behave differently.
Instruction *DummyInst = BinaryOperator::CreateAdd(MaxOccVal, MaxOccVal);
- SmallVector<Value*, 4> NewMulOps;
+ SmallVector<WeakVH, 4> NewMulOps;
for (unsigned i = 0; i != Ops.size(); ++i) {
// Only try to remove factors from expressions we're allowed to.
BinaryOperator *BOp = dyn_cast<BinaryOperator>(Ops[i].Op);
diff --git a/test/Transforms/Reassociate/pr12245.ll b/test/Transforms/Reassociate/pr12245.ll
new file mode 100644
index 0000000000..84098bdb00
--- /dev/null
+++ b/test/Transforms/Reassociate/pr12245.ll
@@ -0,0 +1,50 @@
+; RUN: opt < %s -basicaa -inline -instcombine -reassociate -dse -disable-output
+; PR12245
+
+@a = common global i32 0, align 4
+@d = common global i32 0, align 4
+
+define i32 @fn2() nounwind uwtable ssp {
+entry:
+ %0 = load i32* @a, align 4, !tbaa !0
+ %dec = add nsw i32 %0, -1
+ store i32 %dec, i32* @a, align 4, !tbaa !0
+ %1 = load i32* @d, align 4, !tbaa !0
+ %sub = sub nsw i32 %dec, %1
+ store i32 %sub, i32* @d, align 4, !tbaa !0
+ %2 = load i32* @a, align 4, !tbaa !0
+ %dec1 = add nsw i32 %2, -1
+ store i32 %dec1, i32* @a, align 4, !tbaa !0
+ %3 = load i32* @d, align 4, !tbaa !0
+ %sub2 = sub nsw i32 %dec1, %3
+ store i32 %sub2, i32* @d, align 4, !tbaa !0
+ %4 = load i32* @a, align 4, !tbaa !0
+ %dec3 = add nsw i32 %4, -1
+ store i32 %dec3, i32* @a, align 4, !tbaa !0
+ %5 = load i32* @d, align 4, !tbaa !0
+ %sub4 = sub nsw i32 %dec3, %5
+ store i32 %sub4, i32* @d, align 4, !tbaa !0
+ %6 = load i32* @a, align 4, !tbaa !0
+ %dec5 = add nsw i32 %6, -1
+ store i32 %dec5, i32* @a, align 4, !tbaa !0
+ %7 = load i32* @d, align 4, !tbaa !0
+ %sub6 = sub nsw i32 %dec5, %7
+ store i32 %sub6, i32* @d, align 4, !tbaa !0
+ %8 = load i32* @a, align 4, !tbaa !0
+ %dec7 = add nsw i32 %8, -1
+ store i32 %dec7, i32* @a, align 4, !tbaa !0
+ %9 = load i32* @d, align 4, !tbaa !0
+ %sub8 = sub nsw i32 %dec7, %9
+ store i32 %sub8, i32* @d, align 4, !tbaa !0
+ ret i32 0
+}
+
+define i32 @fn1() nounwind uwtable ssp {
+entry:
+ %call = call i32 @fn2()
+ ret i32 %call
+}
+
+!0 = metadata !{metadata !"int", metadata !1}
+!1 = metadata !{metadata !"omnipotent char", metadata !2}
+!2 = metadata !{metadata !"Simple C/C++ TBAA"}