[Reassociate] Canonicalize constants to RHS operand.
Fix a thinko where the RHS was already a constant.
llvm-svn: 222139
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index 30e9b88..abe7f28 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -332,6 +332,7 @@
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 @@
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();
}