[llvm-commits] [llvm] r110916 - /llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Dan Gohman gohman at apple.com
Thu Aug 12 08:00:23 PDT 2010


Author: djg
Date: Thu Aug 12 10:00:23 2010
New Revision: 110916

URL: http://llvm.org/viewvc/llvm-project?rev=110916&view=rev
Log:
Optimize ScalarEvolution::getAddExpr's operand factoring code by
having it finish processing all of the muliply operands before
starting the whole getAddExpr process over again, instead of
immediately after the first simplification.

Modified:
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=110916&r1=110915&r2=110916&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Thu Aug 12 10:00:23 2010
@@ -1541,6 +1541,7 @@
         }
 
       // Check this multiply against other multiplies being added together.
+      bool AnyFold = false;
       for (unsigned OtherMulIdx = Idx+1;
            OtherMulIdx < Ops.size() && isa<SCEVMulExpr>(Ops[OtherMulIdx]);
            ++OtherMulIdx) {
@@ -1568,12 +1569,14 @@
             const SCEV *InnerMulSum = getAddExpr(InnerMul1,InnerMul2);
             const SCEV *OuterMul = getMulExpr(MulOpSCEV, InnerMulSum);
             if (Ops.size() == 2) return OuterMul;
-            Ops.erase(Ops.begin()+Idx);
-            Ops.erase(Ops.begin()+OtherMulIdx-1);
-            Ops.push_back(OuterMul);
-            return getAddExpr(Ops);
+            Ops[Idx] = OuterMul;
+            Ops.erase(Ops.begin()+OtherMulIdx);
+            OtherMulIdx = Idx;
+            AnyFold = true;
           }
       }
+      if (AnyFold)
+        return getAddExpr(Ops);
     }
   }
 





More information about the llvm-commits mailing list