[polly] r311551 - [ScopDetect] Include zero-iteration loops in loop count.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 06:29:59 PDT 2017


Author: meinersbur
Date: Wed Aug 23 06:29:59 2017
New Revision: 311551

URL: http://llvm.org/viewvc/llvm-project?rev=311551&view=rev
Log:
[ScopDetect] Include zero-iteration loops in loop count.

Loop with zero iteration are, syntactically, loops. They have been
excluded from the loop counter even for the non-profitable counters.
This seems to be unintentially as the sentinel value of '0' minimal
iterations does exclude such loops.

Fix by never considering the iteration count when the sentinel
value of 0 is found.

This makes the recently added NumTotalLoops couter redundant
with NumLoopsOverall, which now is equivalent. Hence, NumTotalLoops
is removed as well.

Note: The test case 'ScopDetect/statistics.ll' effectively does not
check profitability, because -polly-process-unprofitable is passed
to all test cases.

Modified:
    polly/trunk/lib/Analysis/ScopDetection.cpp
    polly/trunk/test/ScopDetect/statistics.ll

Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=311551&r1=311550&r2=311551&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Wed Aug 23 06:29:59 2017
@@ -212,8 +212,6 @@ StringRef polly::PollySkipFnAttr = "poll
 //===----------------------------------------------------------------------===//
 // Statistics.
 
-STATISTIC(NumTotalLoops, "Number of loops (in- or out of scops, in any "
-                         "function processed by Polly)");
 STATISTIC(NumScopRegions, "Number of scops");
 STATISTIC(NumLoopsInScop, "Number of loops in scops");
 STATISTIC(NumScopsDepthOne, "Number of scops with maximal loop depth 1");
@@ -305,17 +303,6 @@ static bool doesStringMatchAnyRegex(Stri
 //===----------------------------------------------------------------------===//
 // ScopDetection.
 
-static void countTotalLoops(Loop *L) {
-  NumTotalLoops++;
-  for (Loop *SubLoop : L->getSubLoops())
-    countTotalLoops(SubLoop);
-}
-
-static void countTotalLoops(LoopInfo &LI) {
-  for (Loop *L : LI)
-    countTotalLoops(L);
-}
-
 ScopDetection::ScopDetection(Function &F, const DominatorTree &DT,
                              ScalarEvolution &SE, LoopInfo &LI, RegionInfo &RI,
                              AliasAnalysis &AA, OptimizationRemarkEmitter &ORE)
@@ -338,7 +325,6 @@ ScopDetection::ScopDetection(Function &F
 
   findScops(*TopRegion);
 
-  countTotalLoops(LI);
   NumScopRegions += ValidRegions.size();
 
   // Prune non-profitable regions.
@@ -1238,10 +1224,11 @@ ScopDetection::countBeneficialSubLoops(L
 
   int NumLoops = 1;
   int MaxLoopDepth = 1;
-  if (auto *TripCountC = dyn_cast<SCEVConstant>(TripCount))
-    if (TripCountC->getType()->getScalarSizeInBits() <= 64)
-      if (TripCountC->getValue()->getZExtValue() <= MinProfitableTrips)
-        NumLoops -= 1;
+  if (MinProfitableTrips > 0)
+    if (auto *TripCountC = dyn_cast<SCEVConstant>(TripCount))
+      if (TripCountC->getType()->getScalarSizeInBits() <= 64)
+        if (TripCountC->getValue()->getZExtValue() <= MinProfitableTrips)
+          NumLoops -= 1;
 
   for (auto &SubLoop : *L) {
     LoopStats Stats = countBeneficialSubLoops(SubLoop, SE, MinProfitableTrips);

Modified: polly/trunk/test/ScopDetect/statistics.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopDetect/statistics.ll?rev=311551&r1=311550&r2=311551&view=diff
==============================================================================
--- polly/trunk/test/ScopDetect/statistics.ll (original)
+++ polly/trunk/test/ScopDetect/statistics.ll Wed Aug 23 06:29:59 2017
@@ -2,20 +2,19 @@
 
 ; REQUIRES: asserts
 
-; CHECK-DAG: 10 polly-detect     - Number of loops (in- or out of scops, in any function processed by Polly)
 ; CHECK-DAG:  4 polly-detect     - Maximal number of loops in scops (profitable scops only)
 ; CHECK-DAG:  4 polly-detect     - Maximal number of loops in scops
-; CHECK-DAG: 10 polly-detect     - Number of loops in scops (profitable scops only)
-; CHECK-DAG: 10 polly-detect     - Number of loops in scops
-; CHECK-DAG: 10 polly-detect     - Number of total loops
-; CHECK-DAG:  4 polly-detect     - Number of scops (profitable scops only)
+; CHECK-DAG: 11 polly-detect     - Number of loops in scops (profitable scops only)
+; CHECK-DAG: 11 polly-detect     - Number of loops in scops
+; CHECK-DAG: 11 polly-detect     - Number of total loops
+; CHECK-DAG:  5 polly-detect     - Number of scops (profitable scops only)
 ; CHECK-DAG:  1 polly-detect     - Number of scops with maximal loop depth 4 (profitable scops only)
-; CHECK-DAG:  1 polly-detect     - Number of scops with maximal loop depth 1 (profitable scops only)
+; CHECK-DAG:  2 polly-detect     - Number of scops with maximal loop depth 1 (profitable scops only)
 ; CHECK-DAG:  1 polly-detect     - Number of scops with maximal loop depth 3 (profitable scops only)
 ; CHECK-DAG:  1 polly-detect     - Number of scops with maximal loop depth 2 (profitable scops only)
-; CHECK-DAG:  4 polly-detect     - Number of scops
+; CHECK-DAG:  5 polly-detect     - Number of scops
 ; CHECK-DAG:  1 polly-detect     - Number of scops with maximal loop depth 4
-; CHECK-DAG:  1 polly-detect     - Number of scops with maximal loop depth 1
+; CHECK-DAG:  2 polly-detect     - Number of scops with maximal loop depth 1
 ; CHECK-DAG:  1 polly-detect     - Number of scops with maximal loop depth 3
 ; CHECK-DAG:  1 polly-detect     - Number of scops with maximal loop depth 2
 
@@ -45,6 +44,10 @@
 ;              A[i + j + k + l] += i + j + k + l;
 ;    }
 ;
+;    void foo_zero_iterations(float *S) {
+;      for (long i = 0; i < 0; i++)
+;        A[i] += i;
+;    }
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 
 define void @foo_1d(float* %A) {
@@ -248,3 +251,28 @@ bb30:
 bb32:                                             ; preds = %bb4
   ret void
 }
+
+define void @foo_zero_iterations(float* %A) {
+bb:
+  br label %bb1
+
+bb1:                                              ; preds = %bb6, %bb
+  %i.0 = phi i64 [ 0, %bb ], [ %tmp7, %bb6 ]
+  %exitcond = icmp ne i64 %i.0, 0
+  br i1 %exitcond, label %bb2, label %bb8
+
+bb2:                                              ; preds = %bb1
+  %tmp = sitofp i64 %i.0 to float
+  %tmp3 = getelementptr inbounds float, float* %A, i64 %i.0
+  %tmp4 = load float, float* %tmp3, align 4
+  %tmp5 = fadd float %tmp4, %tmp
+  store float %tmp5, float* %tmp3, align 4
+  br label %bb6
+
+bb6:                                              ; preds = %bb2
+  %tmp7 = add nuw nsw i64 %i.0, 1
+  br label %bb1
+
+bb8:                                              ; preds = %bb1
+  ret void
+}




More information about the llvm-commits mailing list