[polly] r246433 - ScopDetection: Correctly count the loops in a region
Tobias Grosser via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 31 05:08:11 PDT 2015
Author: grosser
Date: Mon Aug 31 07:08:11 2015
New Revision: 246433
URL: http://llvm.org/viewvc/llvm-project?rev=246433&view=rev
Log:
ScopDetection: Correctly count the loops in a region
There is no reason the loops in a region need to touch either entry or exit
block. Hence, we need to look through all loops that may touch the region as
well as their children to understand if our region has at least two loops.
Added:
polly/trunk/test/ScopDetect/more-than-one-loop.ll
Modified:
polly/trunk/lib/Analysis/ScopDetection.cpp
Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=246433&r1=246432&r2=246433&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Mon Aug 31 07:08:11 2015
@@ -779,19 +779,24 @@ bool ScopDetection::isValidLoop(Loop *L,
}
bool ScopDetection::hasMoreThanOneLoop(Region *R) const {
- Loop *EntryLoop = LI->getLoopFor(R->getEntry());
- if (!EntryLoop)
- return false;
-
- if (!EntryLoop->getSubLoops().empty())
- return true;
-
- for (pred_iterator PI = pred_begin(R->getExit()), PE = pred_end(R->getExit());
- PI != PE; ++PI)
- if (R->contains(*PI))
- if (EntryLoop != LI->getLoopFor(*PI))
- return true;
+ auto LoopNum = 0;
+
+ auto L = LI->getLoopFor(R->getEntry());
+ L = L ? R->outermostLoopInRegion(L) : nullptr;
+ L = L ? L->getParentLoop() : nullptr;
+
+ auto SubLoops =
+ L ? L->getSubLoopsVector() : std::vector<Loop *>(LI->begin(), LI->end());
+ for (auto &SubLoop : SubLoops)
+ if (R->contains(SubLoop)) {
+ LoopNum++;
+ if (SubLoop > 0)
+ LoopNum++;
+
+ if (LoopNum >= 2)
+ return true;
+ }
return false;
}
Added: polly/trunk/test/ScopDetect/more-than-one-loop.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopDetect/more-than-one-loop.ll?rev=246433&view=auto
==============================================================================
--- polly/trunk/test/ScopDetect/more-than-one-loop.ll (added)
+++ polly/trunk/test/ScopDetect/more-than-one-loop.ll Mon Aug 31 07:08:11 2015
@@ -0,0 +1,75 @@
+; RUN: opt %loadPolly -polly-detect-unprofitable=false \
+; RUN: -polly-code-generator=isl \
+; RUN: -polly-detect -analyze < %s | FileCheck %s
+
+; RUN: opt %loadPolly -polly-detect-unprofitable=true \
+; RUN: -polly-code-generator=isl \
+; RUN: -polly-detect -analyze < %s | FileCheck %s
+
+; CHECK: Valid Region for Scop:
+
+; void foo(float *A, float *B, long N) {
+; if (N > 100)
+; for (long i = 0; i < 100; i++)
+; A[i] += i;
+; else
+; for (long i = 0; i < 100; i++)
+; B[i] += i;
+; }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @foo(float* %A, float* %B, i64 %N) {
+bb:
+ %tmp = icmp sgt i64 %N, 100
+ br i1 %tmp, label %bb2, label %bb12
+
+bb2: ; preds = %bb
+ br label %bb3
+
+bb3: ; preds = %bb9, %bb2
+ %i.0 = phi i64 [ 0, %bb2 ], [ %tmp10, %bb9 ]
+ %exitcond = icmp ne i64 %i.0, 100
+ br i1 %exitcond, label %bb4, label %bb11
+
+bb4: ; preds = %bb3
+ %tmp5 = sitofp i64 %i.0 to float
+ %tmp6 = getelementptr inbounds float, float* %A, i64 %i.0
+ %tmp7 = load float, float* %tmp6, align 4
+ %tmp8 = fadd float %tmp7, %tmp5
+ store float %tmp8, float* %tmp6, align 4
+ br label %bb9
+
+bb9: ; preds = %bb4
+ %tmp10 = add nsw i64 %i.0, 1
+ br label %bb3
+
+bb11: ; preds = %bb3
+ br label %bb22
+
+bb12: ; preds = %bb
+ br label %bb13
+
+bb13: ; preds = %bb19, %bb12
+ %i1.0 = phi i64 [ 0, %bb12 ], [ %tmp20, %bb19 ]
+ %exitcond1 = icmp ne i64 %i1.0, 100
+ br i1 %exitcond1, label %bb14, label %bb21
+
+bb14: ; preds = %bb13
+ %tmp15 = sitofp i64 %i1.0 to float
+ %tmp16 = getelementptr inbounds float, float* %B, i64 %i1.0
+ %tmp17 = load float, float* %tmp16, align 4
+ %tmp18 = fadd float %tmp17, %tmp15
+ store float %tmp18, float* %tmp16, align 4
+ br label %bb19
+
+bb19: ; preds = %bb14
+ %tmp20 = add nsw i64 %i1.0, 1
+ br label %bb13
+
+bb21: ; preds = %bb13
+ br label %bb22
+
+bb22: ; preds = %bb21, %bb11
+ ret void
+}
More information about the llvm-commits
mailing list