[llvm] r310237 - [Reassociate] Try to bail out early when canonicalizing.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 6 18:49:09 PDT 2017


Author: davide
Date: Sun Aug  6 18:49:09 2017
New Revision: 310237

URL: http://llvm.org/viewvc/llvm-project?rev=310237&view=rev
Log:
[Reassociate] Try to bail out early when canonicalizing.

This commit rearranges the checks to avoid calls to getRank()
when not needed (e.g. when RHS == LHS).

Modified:
    llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=310237&r1=310236&r2=310237&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Sun Aug  6 18:49:09 2017
@@ -207,13 +207,9 @@ void ReassociatePass::canonicalizeOperan
 
   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();
 }
 




More information about the llvm-commits mailing list