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 | 369c6d270b8bf58faf3f8cdeb3b030dfe6c4f26b (patch) | |
| tree | 2178480bf7a734115a5f07d5266cfc6b8f9a3773 /llvm/lib/Transforms | |
| parent | d32d537d63c01bbc8e060c1ffca6820a188a703d (diff) | |
| download | bcm5719-llvm-369c6d270b8bf58faf3f8cdeb3b030dfe6c4f26b.tar.gz bcm5719-llvm-369c6d270b8bf58faf3f8cdeb3b030dfe6c4f26b.zip | |
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 (!).
llvm-svn: 159426
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/Reassociate.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp index fc7db2e62db..547a51e7d4e 100644 --- a/llvm/lib/Transforms/Scalar/Reassociate.cpp +++ b/llvm/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'); |

