[PATCH] D53189: [SCEV] Avoid redundant computations when doing AddRec merge

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 31 23:21:28 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL345813: [SCEV] Avoid redundant computations when doing AddRec merge (authored by mkazantsev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53189?vs=169958&id=172088#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D53189

Files:
  llvm/trunk/lib/Analysis/ScalarEvolution.cpp
  llvm/trunk/test/Analysis/ScalarEvolution/binomial-explision.ll


Index: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp
@@ -3060,7 +3060,7 @@
       SmallVector<const SCEV*, 7> AddRecOps;
       for (int x = 0, xe = AddRec->getNumOperands() +
              OtherAddRec->getNumOperands() - 1; x != xe && !Overflow; ++x) {
-        const SCEV *Term = getZero(Ty);
+        SmallVector <const SCEV *, 7> SumOps;
         for (int y = x, ye = 2*x+1; y != ye && !Overflow; ++y) {
           uint64_t Coeff1 = Choose(x, 2*x - y, Overflow);
           for (int z = std::max(y-x, y-(int)AddRec->getNumOperands()+1),
@@ -3075,12 +3075,13 @@
             const SCEV *CoeffTerm = getConstant(Ty, Coeff);
             const SCEV *Term1 = AddRec->getOperand(y-z);
             const SCEV *Term2 = OtherAddRec->getOperand(z);
-            Term = getAddExpr(Term, getMulExpr(CoeffTerm, Term1, Term2,
-                                               SCEV::FlagAnyWrap, Depth + 1),
-                              SCEV::FlagAnyWrap, Depth + 1);
+            SumOps.push_back(getMulExpr(CoeffTerm, Term1, Term2,
+                                        SCEV::FlagAnyWrap, Depth + 1));
           }
         }
-        AddRecOps.push_back(Term);
+        if (SumOps.empty())
+          SumOps.push_back(getZero(Ty));
+        AddRecOps.push_back(getAddExpr(SumOps, SCEV::FlagAnyWrap, Depth + 1));
       }
       if (!Overflow) {
         const SCEV *NewAddRec = getAddRecExpr(AddRecOps, AddRec->getLoop(),
Index: llvm/trunk/test/Analysis/ScalarEvolution/binomial-explision.ll
===================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/binomial-explision.ll
+++ llvm/trunk/test/Analysis/ScalarEvolution/binomial-explision.ll
@@ -8,7 +8,7 @@
 define void @test(i32 %x, i64 %y, i1 %cond) {
 
 ; CHECK: %tmp19 = mul i32 %tmp17, %tmp18
-; CHECK: ((((
+; CHECK: ((((((
 ; CHECK-NOT: (((((
 ; CHECK: %tmp20 = add i32 %tmp19, %x
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53189.172088.patch
Type: text/x-patch
Size: 2052 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181101/7a9c4556/attachment.bin>


More information about the llvm-commits mailing list