[PATCH] D32105: [IVUsers] don't bail out of normalizing non-affine add recs

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 17:03:00 PDT 2017


sanjoy created this revision.
Herald added a subscriber: mcrosier.

In a previous change I changed SCEV's normalization / denormalization
to work with non-affine add recs.  So the bailout in IVUsers can be
removed.


https://reviews.llvm.org/D32105

Files:
  lib/Analysis/IVUsers.cpp
  test/Analysis/IVUsers/quadradic-exit-value.ll


Index: test/Analysis/IVUsers/quadradic-exit-value.ll
===================================================================
--- test/Analysis/IVUsers/quadradic-exit-value.ll
+++ test/Analysis/IVUsers/quadradic-exit-value.ll
@@ -29,33 +29,3 @@
   %r = mul i64 %indvar.next, %indvar.next
   ret i64 %r
 }
-
-; PR15470: LSR miscompile. The test2 function should return '1'.
-;
-; SCEV does not know how to denormalize chained recurrences, so make
-; sure they aren't marked as post-inc users.
-;
-; CHECK-LABEL: IV Users for loop %test2.loop
-; CHECK-NO-LCSSA: %sext.us = {0,+,(16777216 + (-16777216 * %sub.us))<nuw><nsw>,+,33554432}<%test2.loop> in %f = ashr i32 %sext.us, 24
-define i32 @test2() {
-entry:
-  br label %test2.loop
-
-test2.loop:
-  %inc1115.us = phi i32 [ 0, %entry ], [ %inc11.us, %test2.loop ]
-  %inc11.us = add nsw i32 %inc1115.us, 1
-  %cmp.us = icmp slt i32 %inc11.us, 2
-  br i1 %cmp.us, label %test2.loop, label %for.end
-
-for.end:
-  %tobool.us = icmp eq i32 %inc1115.us, 0
-  %sub.us = select i1 %tobool.us, i32 0, i32 0
-  %mul.us = shl i32 %inc1115.us, 24
-  %sub.cond.us = sub nsw i32 %inc1115.us, %sub.us
-  %sext.us = mul i32 %mul.us, %sub.cond.us
-  %f = ashr i32 %sext.us, 24
-  br label %exit
-
-exit:
-  ret i32 %f
-}
Index: lib/Analysis/IVUsers.cpp
===================================================================
--- lib/Analysis/IVUsers.cpp
+++ lib/Analysis/IVUsers.cpp
@@ -253,18 +253,8 @@
       const SCEV *OriginalISE = ISE;
 
       auto NormalizePred = [&](const SCEVAddRecExpr *AR) {
-        // We only allow affine AddRecs to be normalized, otherwise we would not
-        // be able to correctly denormalize.
-        // e.g. {1,+,3,+,2} == {-2,+,1,+,2} + {3,+,2}
-        // Normalized form:   {-2,+,1,+,2}
-        // Denormalized form: {1,+,3,+,2}
-        //
-        // However, denormalization would use a different step expression than
-        // normalization (see getPostIncExpr), generating the wrong final
-        // expression: {-2,+,1,+,2} + {1,+,2} => {-1,+,3,+,2}
         auto *L = AR->getLoop();
-        bool Result =
-            AR->isAffine() && IVUseShouldUsePostIncValue(User, I, L, DT);
+        bool Result = IVUseShouldUsePostIncValue(User, I, L, DT);
         if (Result)
           NewUse.PostIncLoops.insert(L);
         return Result;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32105.95366.patch
Type: text/x-patch
Size: 2315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170415/672e64eb/attachment.bin>


More information about the llvm-commits mailing list