diff options
author | Duncan Sands <baldrick@free.fr> | 2012-06-29 13:25:06 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2012-06-29 13:25:06 +0000 |
commit | 96d2eff5c6713a2c5fd2cd61545e49637c332975 (patch) | |
tree | 2f167f6caf1cde3d398501db39d6a49dc98a83f4 | |
parent | 06cb8ed00696eb14d1b831921452e50ec0568ea2 (diff) | |
download | llvm-96d2eff5c6713a2c5fd2cd61545e49637c332975.tar.gz llvm-96d2eff5c6713a2c5fd2cd61545e49637c332975.tar.bz2 llvm-96d2eff5c6713a2c5fd2cd61545e49637c332975.tar.xz |
Fix a reassociate crash on sozefx when compiling with dragonegg+gcc-4.7 due to
the optimizers producing a multiply expression with more multiplications than
the original (!).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159426 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/Reassociate.cpp | 18 | ||||
-rw-r--r-- | test/Transforms/Reassociate/crash.ll | 11 |
2 files changed, 24 insertions, 5 deletions
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp index fc7db2e62d..547a51e7d4 100644 --- a/lib/Transforms/Scalar/Reassociate.cpp +++ b/lib/Transforms/Scalar/Reassociate.cpp @@ -674,8 +674,6 @@ void Reassociate::RewriteExprTree(BinaryOperator *I, // Flags are cleared from the operator in ExpressionChanged up to I inclusive. BinaryOperator *ExpressionChanged = 0; for (unsigned i = 0; ; ++i) { - assert(!NodesToRewrite.empty() && - "Optimized expressions has more nodes than original!"); BinaryOperator *Op = NodesToRewrite.pop_back_val(); // The last operation (which comes earliest in the IR) is special as both @@ -753,9 +751,19 @@ void Reassociate::RewriteExprTree(BinaryOperator *I, } // Otherwise, grab a spare node from the original expression and use that as - // the left-hand side. - assert(!NodesToRewrite.empty() && - "Optimized expressions has more nodes than original!"); + // the left-hand side. If there are no nodes left then the optimizers made + // an expression with more nodes than the original! This usually means that + // they did something stupid but it might mean that the problem was just too + // hard (finding the mimimal number of multiplications needed to realize a + // multiplication expression is NP-complete). Whatever the reason, smart or + // stupid, create a new node if there are none left. + if (NodesToRewrite.empty()) { + Constant *Undef = UndefValue::get(I->getType()); + BinaryOperator *N = BinaryOperator::Create(Instruction::BinaryOps(Opcode), + Undef, Undef, "", I); + NodesToRewrite.push_back(N); + } + DEBUG(dbgs() << "RA: " << *Op << '\n'); Op->setOperand(0, NodesToRewrite.back()); DEBUG(dbgs() << "TO: " << *Op << '\n'); diff --git a/test/Transforms/Reassociate/crash.ll b/test/Transforms/Reassociate/crash.ll index a99c844f01..ce586e15fb 100644 --- a/test/Transforms/Reassociate/crash.ll +++ b/test/Transforms/Reassociate/crash.ll @@ -133,3 +133,14 @@ define i8 @f0(i8 %x) { %t7 = mul i8 %t6, %t0 ret i8 %t7 } + +define i32 @sozefx_(i32 %x, i32 %y) { + %t0 = sub i32 %x, %x + %t1 = mul i32 %t0, %t0 + %t2 = mul i32 %x, %t0 + %t3 = mul i32 %t1, %t1 + %t4 = add i32 %t2, %t3 + %t5 = mul i32 %x, %y + %t6 = add i32 %t4, %t5 + ret i32 %t6 +} |