[Reassociate] Canonicalize constants to RHS operand.

Fix a thinko where the RHS was already a constant.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222139 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chad Rosier
2014-11-17 15:52:51 +00:00
parent 6e61dd242b
commit ae3738f4a7
4 changed files with 10 additions and 7 deletions

View File

@@ -332,6 +332,7 @@ unsigned Reassociate::getRank(Value *V) {
return ValueRankMap[I] = Rank;
}
// Canonicalize constants to RHS. Otherwise, sort the operands by rank.
void Reassociate::canonicalizeOperands(Instruction *I) {
assert(isa<BinaryOperator>(I) && "Expected binary operator.");
assert(I->isCommutative() && "Expected commutative operator.");
@@ -341,7 +342,9 @@ void Reassociate::canonicalizeOperands(Instruction *I) {
unsigned LHSRank = getRank(LHS);
unsigned RHSRank = getRank(RHS);
// Canonicalize constants to RHS. Otherwise, sort the operands by rank.
if (isa<Constant>(RHS))
return;
if (isa<Constant>(LHS) || RHSRank < LHSRank)
cast<BinaryOperator>(I)->swapOperands();
}