[PATCH] D65276: [SCEV] Disable canonical expansion for nested recurrences.

Evgeniy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 6 03:54:16 PDT 2019


ebrevnov updated this revision to Diff 213574.
ebrevnov added a comment.

Wrong changes was uploaded last time. Fixed now.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65276/new/

https://reviews.llvm.org/D65276

Files:
  include/llvm/Analysis/ScalarEvolutionExpressions.h
  lib/Analysis/ScalarEvolution.cpp
  test/Transforms/IndVarSimplify/exit_value_tests.ll


Index: test/Transforms/IndVarSimplify/exit_value_tests.ll
===================================================================
--- test/Transforms/IndVarSimplify/exit_value_tests.ll
+++ test/Transforms/IndVarSimplify/exit_value_tests.ll
@@ -45,34 +45,6 @@
   ret i32 %Y
 }
 
-define i32 @NSquareOver2(i32 %N) {
-; <label>:0
-; CHECK-LABEL: @NSquareOver2(
-; CHECK-NEXT:  Out:
-; CHECK-NEXT:    [[TMP0:%.*]] = zext i32 [[N:%.*]] to i33
-; CHECK-NEXT:    [[TMP1:%.*]] = add i32 [[N]], -1
-; CHECK-NEXT:    [[TMP2:%.*]] = zext i32 [[TMP1]] to i33
-; CHECK-NEXT:    [[TMP3:%.*]] = mul i33 [[TMP0]], [[TMP2]]
-; CHECK-NEXT:    [[TMP4:%.*]] = lshr i33 [[TMP3]], 1
-; CHECK-NEXT:    [[TMP5:%.*]] = trunc i33 [[TMP4]] to i32
-; CHECK-NEXT:    [[TMP6:%.*]] = add i32 [[N]], [[TMP5]]
-; CHECK-NEXT:    [[TMP7:%.*]] = add i32 [[TMP6]], 15
-; CHECK-NEXT:    ret i32 [[TMP7]]
-;
-  br label %Loop
-
-Loop:		; preds = %Loop, %0
-  %X = phi i32 [ 0, %0 ], [ %X2, %Loop ]		; <i32> [#uses=3]
-  %Y = phi i32 [ 15, %0 ], [ %Y2, %Loop ]		; <i32> [#uses=1]
-  %Y2 = add i32 %Y, %X		; <i32> [#uses=2]
-  %X2 = add i32 %X, 1		; <i32> [#uses=1]
-  %c = icmp eq i32 %X, %N		; <i1> [#uses=1]
-  br i1 %c, label %Out, label %Loop
-
-Out:		; preds = %Loop
-  ret i32 %Y2
-}
-
 define i32 @strength_reduced() {
 ; <label>:0
 ; CHECK-LABEL: @strength_reduced(
Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -1204,6 +1204,13 @@
   IntegerType *CalculationTy = IntegerType::get(SE.getContext(),
                                                       CalculationBits);
   const SCEV *Dividend = SE.getTruncateOrZeroExtend(It, CalculationTy);
+
+  // Zero extension indicates insufficient precision of incoming "It".
+  // In this case result of calculations may be incorrect. Go ahead and return
+  // SCEVCouldNotCompute.
+  if (isa<SCEVZeroExtendExpr>(Dividend))
+    return SE.getCouldNotCompute();
+
   for (unsigned i = 1; i != K; ++i) {
     const SCEV *S = SE.getMinusSCEV(It, SE.getConstant(It->getType(), i));
     Dividend = SE.getMulExpr(Dividend,
@@ -11660,7 +11667,7 @@
       return (L && !L->contains(I)) ? LoopInvariant : LoopVariant;
     return LoopInvariant;
   case scCouldNotCompute:
-    llvm_unreachable("Attempt to use a SCEVCouldNotCompute object!");
+    return LoopVariant;
   }
   llvm_unreachable("Unknown SCEV kind!");
 }
Index: include/llvm/Analysis/ScalarEvolutionExpressions.h
===================================================================
--- include/llvm/Analysis/ScalarEvolutionExpressions.h
+++ include/llvm/Analysis/ScalarEvolutionExpressions.h
@@ -343,6 +343,10 @@
 
     /// Return the value of this chain of recurrences at the specified
     /// iteration number.
+    ///
+    /// Note that SCEVCouldNotCompute is returned if evaluation attempt failed.
+    /// For example, if precision of \p It is less than required to perform an
+    /// evaluation instance of SCEVCouldNotCompute is returned.
     const SCEV *evaluateAtIteration(const SCEV *It, ScalarEvolution &SE) const;
 
     /// Return the number of iterations of this loop that produce


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65276.213574.patch
Type: text/x-patch
Size: 3200 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190806/411cba56/attachment.bin>


More information about the llvm-commits mailing list