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

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 17 00:58:50 PDT 2018


mkazantsev updated this revision to Diff 169958.
mkazantsev added a comment.

Rebased: the patch slightly alters simplification, but in this test the expression is still within reasonable bounds.


https://reviews.llvm.org/D53189

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


Index: test/Analysis/ScalarEvolution/binomial-explision.ll
===================================================================
--- test/Analysis/ScalarEvolution/binomial-explision.ll
+++ 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
 
Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ 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(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53189.169958.patch
Type: text/x-patch
Size: 1986 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181017/d0864e5e/attachment.bin>


More information about the llvm-commits mailing list