llvm.org GIT mirror llvm / df46b90
Merging r168291: into the 3.2 release branch. Fix PR14060, an infinite loop in reassociate. The problem was that one of the operands of the expression being written was wrongly thought to be reusable as an inner node of the expression resulting in it turning up as both an inner node *and* a leaf, creating a cycle in the def-use graph. This would have caused the verifier to blow up if things had gotten that far, however it managed to provoke an infinite loop first. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_32@168489 91177308-0d34-0410-b5e6-96231b3b80d8 Pawel Wodnicki 6 years ago
2 changed file(s) with 43 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
605605 SmallVectorImpl &Ops) {
606606 assert(Ops.size() > 1 && "Single values should be used directly!");
607607
608 // Since our optimizations never increase the number of operations, the new
609 // expression can always be written by reusing the existing binary operators
608 // Since our optimizations should never increase the number of operations, the
609 // new expression can usually be written reusing the existing binary operators
610610 // from the original expression tree, without creating any new instructions,
611611 // though the rewritten expression may have a completely different topology.
612612 // We take care to not change anything if the new expression will be the same
619619 SmallVector NodesToRewrite;
620620 unsigned Opcode = I->getOpcode();
621621 BinaryOperator *Op = I;
622
623 /// NotRewritable - The operands being written will be the leaves of the new
624 /// expression and must not be used as inner nodes (via NodesToRewrite) by
625 /// mistake. Inner nodes are always reassociable, and usually leaves are not
626 /// (if they were they would have been incorporated into the expression and so
627 /// would not be leaves), so most of the time there is no danger of this. But
628 /// in rare cases a leaf may become reassociable if an optimization kills uses
629 /// of it, or it may momentarily become reassociable during rewriting (below)
630 /// due it being removed as an operand of one of its uses. Ensure that misuse
631 /// of leaf nodes as inner nodes cannot occur by remembering all of the future
632 /// leaves and refusing to reuse any of them as inner nodes.
633 SmallPtrSet NotRewritable;
634 for (unsigned i = 0, e = Ops.size(); i != e; ++i)
635 NotRewritable.insert(Ops[i].Op);
622636
623637 // ExpressionChanged - Non-null if the rewritten expression differs from the
624638 // original in some non-trivial way, requiring the clearing of optional flags.
652666 // the old operands with the new ones.
653667 DEBUG(dbgs() << "RA: " << *Op << '\n');
654668 if (NewLHS != OldLHS) {
655 if (BinaryOperator *BO = isReassociableOp(OldLHS, Opcode))
669 BinaryOperator *BO = isReassociableOp(OldLHS, Opcode);
670 if (BO && !NotRewritable.count(BO))
656671 NodesToRewrite.push_back(BO);
657672 Op->setOperand(0, NewLHS);
658673 }
659674 if (NewRHS != OldRHS) {
660 if (BinaryOperator *BO = isReassociableOp(OldRHS, Opcode))
675 BinaryOperator *BO = isReassociableOp(OldRHS, Opcode);
676 if (BO && !NotRewritable.count(BO))
661677 NodesToRewrite.push_back(BO);
662678 Op->setOperand(1, NewRHS);
663679 }
681697 Op->swapOperands();
682698 } else {
683699 // Overwrite with the new right-hand side.
684 if (BinaryOperator *BO = isReassociableOp(Op->getOperand(1), Opcode))
700 BinaryOperator *BO = isReassociableOp(Op->getOperand(1), Opcode);
701 if (BO && !NotRewritable.count(BO))
685702 NodesToRewrite.push_back(BO);
686703 Op->setOperand(1, NewRHS);
687704 ExpressionChanged = Op;
694711 // Now deal with the left-hand side. If this is already an operation node
695712 // from the original expression then just rewrite the rest of the expression
696713 // into it.
697 if (BinaryOperator *BO = isReassociableOp(Op->getOperand(0), Opcode)) {
714 BinaryOperator *BO = isReassociableOp(Op->getOperand(0), Opcode);
715 if (BO && !NotRewritable.count(BO)) {
698716 Op = BO;
699717 continue;
700718 }
152152 %ret = add i32 %tmp2, %tmp3
153153 ret i32 %ret
154154 }
155
156 ; PR14060
157 define i8 @hang(i8 %p, i8 %p0, i8 %p1, i8 %p2, i8 %p3, i8 %p4, i8 %p5, i8 %p6, i8 %p7, i8 %p8, i8 %p9) {
158 %tmp = zext i1 false to i8
159 %tmp16 = or i8 %tmp, 1
160 %tmp22 = or i8 %p7, %p0
161 %tmp23 = or i8 %tmp16, %tmp22
162 %tmp28 = or i8 %p9, %p1
163 %tmp31 = or i8 %tmp23, %p2
164 %tmp32 = or i8 %tmp31, %tmp28
165 %tmp38 = or i8 %p8, %p3
166 %tmp39 = or i8 %tmp16, %tmp38
167 %tmp43 = or i8 %tmp39, %p4
168 %tmp44 = or i8 %tmp43, 1
169 %tmp47 = or i8 %tmp32, %p5
170 %tmp50 = or i8 %tmp47, %p6
171 %tmp51 = or i8 %tmp44, %tmp50
172 ret i8 %tmp51
173 }