fix an infinite loop in reassociate building emacs.
[oota-llvm.git] / lib / Transforms / Scalar / Reassociate.cpp
index 564036bba3ed91a7a71f411d0c8aa5bf91a7fa01..f2a8633f97ade6696896cd12b923726b6017de36 100644 (file)
@@ -932,6 +932,10 @@ void Reassociate::ReassociateBB(BasicBlock *BB) {
     if (BI->getOpcode() == Instruction::Sub) {
       if (ShouldBreakUpSubtract(BI)) {
         BI = BreakUpSubtract(BI, ValueRankMap);
+        // Reset the BBI iterator in case BreakUpSubtract changed the
+        // instruction it points to.
+        BBI = BI;
+        ++BBI;
         MadeChange = true;
       } else if (BinaryOperator::isNeg(BI)) {
         // Otherwise, this is a negation.  See if the operand is a multiply tree