]> granicus.if.org Git - llvm/commitdiff
[Reassociate] Try to bail out early when canonicalizing.
authorDavide Italiano <davide@freebsd.org>
Mon, 7 Aug 2017 01:49:09 +0000 (01:49 +0000)
committerDavide Italiano <davide@freebsd.org>
Mon, 7 Aug 2017 01:49:09 +0000 (01:49 +0000)
This commit rearranges the checks to avoid calls to getRank()
when not needed (e.g. when RHS == LHS).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310237 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/Reassociate.cpp

index 29d1ba406ae49efa898d4b495597d951f150a63d..404daa741e1ebb007c60568626dd1c9a832ed65e 100644 (file)
@@ -207,13 +207,9 @@ void ReassociatePass::canonicalizeOperands(Instruction *I) {
 
   Value *LHS = I->getOperand(0);
   Value *RHS = I->getOperand(1);
-  unsigned LHSRank = getRank(LHS);
-  unsigned RHSRank = getRank(RHS);
-
-  if (isa<Constant>(RHS))
+  if (LHS == RHS || isa<Constant>(RHS))
     return;
-
-  if (isa<Constant>(LHS) || RHSRank < LHSRank)
+  if (isa<Constant>(LHS) || getRank(RHS) < getRank(LHS))
     cast<BinaryOperator>(I)->swapOperands();
 }