[Reassociate] As the expression tree is rewritten make sure the operands are

emitted in canonical form.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222142 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chad Rosier
2014-11-17 16:33:50 +00:00
parent 19e8fe05dc
commit 14915fe523
17 changed files with 54 additions and 53 deletions

View File

@@ -791,14 +791,11 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
Value *OldLHS = Op->getOperand(0);
Value *OldRHS = Op->getOperand(1);
if (NewLHS == OldLHS && NewRHS == OldRHS)
// Nothing changed, leave it alone.
break;
if (NewLHS == OldRHS && NewRHS == OldLHS) {
// The order of the operands was reversed. Swap them.
// The new operation differs trivially from the original.
if ((NewLHS == OldLHS && NewRHS == OldRHS) ||
(NewLHS == OldRHS && NewRHS == OldLHS)) {
DEBUG(dbgs() << "RA: " << *Op << '\n');
Op->swapOperands();
canonicalizeOperands(Op);
DEBUG(dbgs() << "TO: " << *Op << '\n');
MadeChange = true;
++NumChanged;
@@ -820,6 +817,8 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
NodesToRewrite.push_back(BO);
Op->setOperand(1, NewRHS);
}
// Put the operands in canonical form.
canonicalizeOperands(Op);
DEBUG(dbgs() << "TO: " << *Op << '\n');
ExpressionChanged = Op;
@@ -856,6 +855,7 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
// into it.
BinaryOperator *BO = isReassociableOp(Op->getOperand(0), Opcode);
if (BO && !NotRewritable.count(BO)) {
canonicalizeOperands(Op);
Op = BO;
continue;
}
@@ -880,6 +880,7 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
DEBUG(dbgs() << "RA: " << *Op << '\n');
Op->setOperand(0, NewOp);
canonicalizeOperands(Op);
DEBUG(dbgs() << "TO: " << *Op << '\n');
ExpressionChanged = Op;
MadeChange = true;