[polly] r270060 - Optimistic assume required invariant loads to be invariant
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Thu May 19 06:24:11 PDT 2016
Author: jdoerfert
Date: Thu May 19 08:24:10 2016
New Revision: 270060
URL: http://llvm.org/viewvc/llvm-project?rev=270060&view=rev
Log:
Optimistic assume required invariant loads to be invariant
So far we bailed if a required invariant load was potentially overwritten in
the SCoP. From now on we will optimistically assume it is actually invariant
and, to this end, restrict the valid parameter space.
Modified:
polly/trunk/include/polly/ScopInfo.h
polly/trunk/lib/Analysis/ScopInfo.cpp
polly/trunk/test/ScopInfo/NonAffine/non_affine_conditional_surrounding_affine_loop.ll
polly/trunk/test/ScopInfo/NonAffine/non_affine_conditional_surrounding_non_affine_loop.ll
polly/trunk/test/ScopInfo/remarks.ll
Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=270060&r1=270059&r2=270060&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Thu May 19 08:24:10 2016
@@ -2036,6 +2036,9 @@ public:
const InvariantLoadsSetTy &getRequiredInvariantLoads() const {
return DC.RequiredILS;
}
+ bool isRequiredInvariantLoad(LoadInst *LI) const {
+ return getRequiredInvariantLoads().count(LI);
+ }
const BoxedLoopsSetTy &getBoxedLoops() const { return DC.BoxedLoopsSet; }
bool isNonAffineSubRegion(const Region *R) {
return DC.NonAffineSubRegionSet.count(R);
Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=270060&r1=270059&r2=270060&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Thu May 19 08:24:10 2016
@@ -3418,7 +3418,8 @@ bool Scop::isHoistableAccess(MemoryAcces
// Skip accesses in non-affine subregions as they might not be executed
// under the same condition as the entry of the non-affine subregion.
- if (BB != Access->getAccessInstruction()->getParent())
+ auto *LI = dyn_cast<LoadInst>(Access->getAccessInstruction());
+ if (!LI || BB != LI->getParent())
return false;
isl_map *AccessRelation = Access->getAccessRelation();
@@ -3436,12 +3437,17 @@ bool Scop::isHoistableAccess(MemoryAcces
isl_union_map *Written = isl_union_map_intersect_range(
isl_union_map_copy(Writes), isl_union_set_from_set(AccessRange));
bool IsWritten = !isl_union_map_is_empty(Written);
- isl_union_map_free(Written);
- if (IsWritten)
- return false;
+ if (IsWritten && isRequiredInvariantLoad(LI)) {
+ auto *WrittenCtx = isl_union_map_params(Written);
+ WrittenCtx = isl_set_remove_divs(WrittenCtx);
+ addAssumption(INVARIANTLOAD, WrittenCtx, LI->getDebugLoc(), AS_RESTRICTION);
+ IsWritten = false;
+ } else {
+ isl_union_map_free(Written);
+ }
- return true;
+ return !IsWritten;
}
void Scop::verifyInvariantLoads() {
Modified: polly/trunk/test/ScopInfo/NonAffine/non_affine_conditional_surrounding_affine_loop.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/NonAffine/non_affine_conditional_surrounding_affine_loop.ll?rev=270060&r1=270059&r2=270060&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/NonAffine/non_affine_conditional_surrounding_affine_loop.ll (original)
+++ polly/trunk/test/ScopInfo/NonAffine/non_affine_conditional_surrounding_affine_loop.ll Thu May 19 08:24:10 2016
@@ -9,8 +9,7 @@
; Negative test for INNERMOST.
; At the moment we will optimistically assume A[i] in the conditional before the inner
; loop might be invariant and expand the SCoP from the loop to include the conditional. However,
-; during SCoP generation we will realize that A[i] is in fact not invariant (in this region = the body
-; of the outer loop) and bail.
+; during SCoP generation we will realize that A[i] is in not always invariant.
;
; Possible solutions could be:
; - Do not optimistically assume it to be invariant (as before this commit), however we would loose
@@ -18,7 +17,51 @@
; - Reduce the size of the SCoP if an assumed invariant access is in fact not invariant instead of
; rejecting the whole region.
;
-; INNERMOST-NOT: Function: f
+; INNERMOST: Function: f
+; INNERMOST-NEXT: Region: %bb4---%bb3
+; INNERMOST-NEXT: Max Loop Depth: 1
+; INNERMOST-NEXT: Invariant Accesses: {
+; INNERMOST-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0]
+; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb4[] -> MemRef_A[p_2] };
+; INNERMOST-NEXT: Execution Context: [tmp6, N, p_2] -> { : }
+; INNERMOST-NEXT: }
+; INNERMOST-NEXT: Context:
+; INNERMOST-NEXT: [tmp6, N, p_2] -> { : -2147483648 <= tmp6 <= 2147483647 and -2147483648 <= N <= 2147483647 and 0 <= p_2 <= 1024 }
+; INNERMOST-NEXT: Assumed Context:
+; INNERMOST-NEXT: [tmp6, N, p_2] -> { : }
+; INNERMOST-NEXT: Invalid Context:
+; INNERMOST-NEXT: [tmp6, N, p_2] -> { : p_2 < N and (tmp6 < 0 or tmp6 > 0) }
+; INNERMOST-NEXT: p0: %tmp6
+; INNERMOST-NEXT: p1: %N
+; INNERMOST-NEXT: p2: {0,+,1}<nuw><nsw><%bb3>
+; INNERMOST-NEXT: Arrays {
+; INNERMOST-NEXT: i32 MemRef_A[*]; // Element size 4
+; INNERMOST-NEXT: i64 MemRef_indvars_iv_next2; // Element size 8
+; INNERMOST-NEXT: }
+; INNERMOST-NEXT: Arrays (Bounds as pw_affs) {
+; INNERMOST-NEXT: i32 MemRef_A[*]; // Element size 4
+; INNERMOST-NEXT: i64 MemRef_indvars_iv_next2; // Element size 8
+; INNERMOST-NEXT: }
+; INNERMOST-NEXT: Alias Groups (0):
+; INNERMOST-NEXT: n/a
+; INNERMOST-NEXT: Statements {
+; INNERMOST-NEXT: Stmt_bb11
+; INNERMOST-NEXT: Domain :=
+; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb11[i0] : 0 <= i0 < N and (tmp6 < 0 or tmp6 > 0) };
+; INNERMOST-NEXT: Schedule :=
+; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb11[i0] -> [0, i0] : tmp6 < 0 or tmp6 > 0 };
+; INNERMOST-NEXT: ReadAccess := [Reduction Type: +] [Scalar: 0]
+; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb11[i0] -> MemRef_A[i0] };
+; INNERMOST-NEXT: MustWriteAccess := [Reduction Type: +] [Scalar: 0]
+; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb11[i0] -> MemRef_A[i0] };
+; INNERMOST-NEXT: Stmt_bb18
+; INNERMOST-NEXT: Domain :=
+; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb18[] };
+; INNERMOST-NEXT: Schedule :=
+; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb18[] -> [1, 0] };
+; INNERMOST-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1]
+; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb18[] -> MemRef_indvars_iv_next2[] };
+; INNERMOST-NEXT: }
;
; ALL: Function: f
; ALL-NEXT: Region: %bb3---%bb19
Modified: polly/trunk/test/ScopInfo/NonAffine/non_affine_conditional_surrounding_non_affine_loop.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/NonAffine/non_affine_conditional_surrounding_non_affine_loop.ll?rev=270060&r1=270059&r2=270060&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/NonAffine/non_affine_conditional_surrounding_non_affine_loop.ll (original)
+++ polly/trunk/test/ScopInfo/NonAffine/non_affine_conditional_surrounding_non_affine_loop.ll Thu May 19 08:24:10 2016
@@ -13,8 +13,7 @@
; Negative test for INNERMOST.
; At the moment we will optimistically assume A[i] in the conditional before the inner
; loop might be invariant and expand the SCoP from the loop to include the conditional. However,
-; during SCoP generation we will realize that A[i] is in fact not invariant (in this region = the body
-; of the outer loop) and bail.
+; during SCoP generation we will realize that A[i] is only sometimes invariant.
;
; Possible solutions could be:
; - Do not optimistically assume it to be invariant (as before this commit), however we would loose
@@ -22,7 +21,51 @@
; - Reduce the size of the SCoP if an assumed invariant access is in fact not invariant instead of
; rejecting the whole region.
;
-; INNERMOST-NOT: Function: f
+; INNERMOST: Function: f
+; INNERMOST-NEXT: Region: %bb4---%bb3
+; INNERMOST-NEXT: Max Loop Depth: 1
+; INNERMOST-NEXT: Invariant Accesses: {
+; INNERMOST-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0]
+; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb4[] -> MemRef_A[p_2] };
+; INNERMOST-NEXT: Execution Context: [tmp6, p_1, p_2] -> { : }
+; INNERMOST-NEXT: }
+; INNERMOST-NEXT: Context:
+; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { : -2147483648 <= tmp6 <= 2147483647 and -2199023255552 <= p_1 <= 2199023254528 and 0 <= p_2 <= 1024 }
+; INNERMOST-NEXT: Assumed Context:
+; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { : }
+; INNERMOST-NEXT: Invalid Context:
+; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { : p_2 < p_1 and (tmp6 < 0 or tmp6 > 0) }
+; INNERMOST-NEXT: p0: %tmp6
+; INNERMOST-NEXT: p1: {0,+,(sext i32 %N to i64)}<%bb3>
+; INNERMOST-NEXT: p2: {0,+,1}<nuw><nsw><%bb3>
+; INNERMOST-NEXT: Arrays {
+; INNERMOST-NEXT: i32 MemRef_A[*]; // Element size 4
+; INNERMOST-NEXT: i64 MemRef_indvars_iv_next2; // Element size 8
+; INNERMOST-NEXT: }
+; INNERMOST-NEXT: Arrays (Bounds as pw_affs) {
+; INNERMOST-NEXT: i32 MemRef_A[*]; // Element size 4
+; INNERMOST-NEXT: i64 MemRef_indvars_iv_next2; // Element size 8
+; INNERMOST-NEXT: }
+; INNERMOST-NEXT: Alias Groups (0):
+; INNERMOST-NEXT: n/a
+; INNERMOST-NEXT: Statements {
+; INNERMOST-NEXT: Stmt_bb12
+; INNERMOST-NEXT: Domain :=
+; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb12[i0] : 0 <= i0 < p_1 and (tmp6 < 0 or tmp6 > 0) };
+; INNERMOST-NEXT: Schedule :=
+; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb12[i0] -> [0, i0] : tmp6 < 0 or tmp6 > 0 };
+; INNERMOST-NEXT: ReadAccess := [Reduction Type: +] [Scalar: 0]
+; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb12[i0] -> MemRef_A[i0] };
+; INNERMOST-NEXT: MustWriteAccess := [Reduction Type: +] [Scalar: 0]
+; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb12[i0] -> MemRef_A[i0] };
+; INNERMOST-NEXT: Stmt_bb19
+; INNERMOST-NEXT: Domain :=
+; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb19[] };
+; INNERMOST-NEXT: Schedule :=
+; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb19[] -> [1, 0] };
+; INNERMOST-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1]
+; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb19[] -> MemRef_indvars_iv_next2[] };
+; INNERMOST-NEXT: }
;
; ALL: Function: f
; ALL-NEXT: Region: %bb3---%bb20
Modified: polly/trunk/test/ScopInfo/remarks.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/remarks.ll?rev=270060&r1=270059&r2=270060&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/remarks.ll (original)
+++ polly/trunk/test/ScopInfo/remarks.ll Thu May 19 08:24:10 2016
@@ -10,7 +10,7 @@
; CHECK: remark: test/ScopInfo/remarks.c:9:15: Possibly aliasing pointer, use restrict keyword.
; CHECK: remark: test/ScopInfo/remarks.c:14:3: SCoP ends here.
; CHECK: remark: test/ScopInfo/remarks.c:19:3: SCoP begins here.
-; CHECK: remark: test/ScopInfo/remarks.c:21:11: Invariant load assumption: [tmp] -> { : 1 = 0 }
+; CHECK: remark: test/ScopInfo/remarks.c:21:11: Invariant load restriction: [tmp] -> { : tmp < 0 or tmp > 0 }
; CHECK: remark: test/ScopInfo/remarks.c:22:16: SCoP ends here but was dismissed.
;
; #include <stdio.h>
More information about the llvm-commits
mailing list