[polly] r301582 - [ScopInfo] Consider only write-free dereferencable loads as invariant

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 27 13:08:16 PDT 2017


Author: grosser
Date: Thu Apr 27 15:08:16 2017
New Revision: 301582

URL: http://llvm.org/viewvc/llvm-project?rev=301582&view=rev
Log:
[ScopInfo] Consider only write-free dereferencable loads as invariant

When we introduced in r297375 support for hoisting loads that are known
to be dereferencable without any conditional guard, we forgot to keep the check
to verify that no other write into the very same location exists. This
change ensures now that dereferencable loads are allowed to access everything,
but can only be hoisted in case no conflicting write exists.

This resolves llvm.org/PR32778

Reported-by: Huihui Zhang <huihuiz at codeaurora.org>

Modified:
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/test/Isl/CodeGen/reduction_2.ll

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=301582&r1=301581&r2=301582&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Thu Apr 27 15:08:16 2017
@@ -3737,16 +3737,6 @@ __isl_give isl_set *Scop::getNonHoistabl
   if (hasNonHoistableBasePtrInScop(Access, Writes))
     return nullptr;
 
-  auto &DL = getFunction().getParent()->getDataLayout();
-  if (isSafeToLoadUnconditionally(LI->getPointerOperand(), LI->getAlignment(),
-                                  DL))
-    return isl_set_empty(getParamSpace());
-
-  // 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 != LI->getParent())
-    return nullptr;
-
   isl_map *AccessRelation = Access->getAccessRelation();
   assert(!isl_map_is_empty(AccessRelation));
 
@@ -3757,10 +3747,25 @@ __isl_give isl_set *Scop::getNonHoistabl
   }
 
   AccessRelation = isl_map_intersect_domain(AccessRelation, Stmt.getDomain());
-  isl_set *AccessRange = isl_map_range(AccessRelation);
+  isl_set *SafeToLoad;
+
+  auto &DL = getFunction().getParent()->getDataLayout();
+  if (isSafeToLoadUnconditionally(LI->getPointerOperand(), LI->getAlignment(),
+                                  DL)) {
+    SafeToLoad =
+        isl_set_universe(isl_space_range(isl_map_get_space(AccessRelation)));
+    isl_map_free(AccessRelation);
+  } else if (BB != LI->getParent()) {
+    // Skip accesses in non-affine subregions as they might not be executed
+    // under the same condition as the entry of the non-affine subregion.
+    isl_map_free(AccessRelation);
+    return nullptr;
+  } else {
+    SafeToLoad = isl_map_range(AccessRelation);
+  }
 
   isl_union_map *Written = isl_union_map_intersect_range(
-      isl_union_map_copy(Writes), isl_union_set_from_set(AccessRange));
+      isl_union_map_copy(Writes), isl_union_set_from_set(SafeToLoad));
   auto *WrittenCtx = isl_union_map_params(Written);
   bool IsWritten = !isl_set_is_empty(WrittenCtx);
 

Modified: polly/trunk/test/Isl/CodeGen/reduction_2.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/reduction_2.ll?rev=301582&r1=301581&r2=301582&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/reduction_2.ll (original)
+++ polly/trunk/test/Isl/CodeGen/reduction_2.ll Thu Apr 27 15:08:16 2017
@@ -89,13 +89,10 @@ if.end:
 
 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
 
-; At some point this was a negative test, where we optimistically assumed RED[0]
-; in the conditional after the loop is invariant and expanded the SCoP from
-; the loop to include the conditional. However, during SCoP generation we
-; realized that RED[0] is in fact not invariant and bailed.
+; This is a negative test. We can prove that RED[0] in the conditional after
+; the loop is dereferencable and consequently expand the SCoP from the
+; loop to include the conditional. However, during SCoP generation we realize
+; that, while RED[0] is invariant, it is written to as part of the same scop
+; and can consequently not be hoisted. Hence, we invalidate the scop.
 ;
-; Today, LLVM can derive that the load is indeed invariant and Polly uses this
-; information to unconditionally invariant load hoist RED[0].
-;
-; CHECK: for (int c0 = 0; c0 <= 1018; c0 += 1)
-; CHECK-NEXT:   Stmt_for_body(c0);
+; CHECK-NOT: for (int c0 = 0; c0 <= 1018; c0 += 1)




More information about the llvm-commits mailing list