[llvm] r316739 - Revert rL316568 because of sudden performance drop on ARM

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 26 21:17:44 PDT 2017


Author: mkazantsev
Date: Thu Oct 26 21:17:44 2017
New Revision: 316739

URL: http://llvm.org/viewvc/llvm-project?rev=316739&view=rev
Log:
Revert rL316568 because of sudden performance drop on ARM

Modified:
    llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
    llvm/trunk/test/Transforms/IndVarSimplify/udiv.ll

Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=316739&r1=316738&r2=316739&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Thu Oct 26 21:17:44 2017
@@ -2250,6 +2250,10 @@ namespace {
 // only needed when the expression includes some subexpression that is not IV
 // derived.
 //
+// Currently, we only allow division by a nonzero constant here. If this is
+// inadequate, we could easily allow division by SCEVUnknown by using
+// ValueTracking to check isKnownNonZero().
+//
 // We cannot generally expand recurrences unless the step dominates the loop
 // header. The expander handles the special case of affine recurrences by
 // scaling the recurrence outside the loop, but this technique isn't generally
@@ -2264,11 +2268,13 @@ struct SCEVFindUnsafe {
 
   bool follow(const SCEV *S) {
     if (const SCEVUDivExpr *D = dyn_cast<SCEVUDivExpr>(S)) {
-      if (!SE.isKnownNonZero(D->getRHS())) {
+      const SCEVConstant *SC = dyn_cast<SCEVConstant>(D->getRHS());
+      if (!SC || SC->getValue()->isZero()) {
         IsUnsafe = true;
         return false;
       }
-    } else if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(S)) {
+    }
+    if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(S)) {
       const SCEV *Step = AR->getStepRecurrence(SE);
       if (!AR->isAffine() && !SE.dominates(Step, AR->getLoop()->getHeader())) {
         IsUnsafe = true;

Modified: llvm/trunk/test/Transforms/IndVarSimplify/udiv.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/udiv.ll?rev=316739&r1=316738&r2=316739&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/udiv.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/udiv.ll Thu Oct 26 21:17:44 2017
@@ -130,11 +130,11 @@ declare i32 @printf(i8* nocapture, ...)
 ; IndVars doesn't emit a udiv in for.body.preheader since SCEVExpander::expand will
 ; find out there's already a udiv in the original code.
 
-; CHECK-LABEL: @foo_01(
+; CHECK-LABEL: @foo(
 ; CHECK: for.body.preheader:
 ; CHECK-NOT: udiv
 
-define void @foo_01(double* %p, i64 %n) nounwind {
+define void @foo(double* %p, i64 %n) nounwind {
 entry:
   %div0 = udiv i64 %n, 7                          ; <i64> [#uses=1]
   %div1 = add i64 %div0, 1
@@ -160,39 +160,3 @@ for.end.loopexit:
 for.end:                                          ; preds = %for.end.loopexit, %entry
   ret void
 }
-
-; Same as foo_01, but we divide by non-constant value.
-
-; CHECK-LABEL: @foo_02(
-; CHECK: for.body.preheader:
-; CHECK-NOT: udiv
-
-define void @foo_02(double* %p, i64 %n, i64* %lp) nounwind {
-entry:
-  %denom = load i64, i64* %lp, align 4, !range !0
-  %div0 = udiv i64 %n, %denom                          ; <i64> [#uses=1]
-  %div1 = add i64 %div0, 1
-  %cmp2 = icmp ult i64 0, %div1                   ; <i1> [#uses=1]
-  br i1 %cmp2, label %for.body.preheader, label %for.end
-
-for.body.preheader:                               ; preds = %entry
-  br label %for.body
-
-for.body:                                         ; preds = %for.body.preheader, %for.body
-  %i.03 = phi i64 [ %inc, %for.body ], [ 0, %for.body.preheader ] ; <i64> [#uses=2]
-  %arrayidx = getelementptr inbounds double, double* %p, i64 %i.03 ; <double*> [#uses=1]
-  store double 0.000000e+00, double* %arrayidx
-  %inc = add i64 %i.03, 1                         ; <i64> [#uses=2]
-  %divx = udiv i64 %n, %denom                           ; <i64> [#uses=1]
-  %div = add i64 %divx, 1
-  %cmp = icmp ult i64 %inc, %div                  ; <i1> [#uses=1]
-  br i1 %cmp, label %for.body, label %for.end.loopexit
-
-for.end.loopexit:                                 ; preds = %for.body
-  br label %for.end
-
-for.end:                                          ; preds = %for.end.loopexit, %entry
-  ret void
-}
-
-!0 = !{i64 1, i64 10}




More information about the llvm-commits mailing list