[polly] r286444 - SCEVAffinator: pass parameter-only set to addRestriction if BB=nullptr

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 10 03:44:10 PST 2016


Author: grosser
Date: Thu Nov 10 05:44:10 2016
New Revision: 286444

URL: http://llvm.org/viewvc/llvm-project?rev=286444&view=rev
Log:
SCEVAffinator: pass parameter-only set to addRestriction if BB=nullptr

Assumptions can either be added for a given basic block, in which case the set
describing the assumptions is expected to match the dimensions of its domain.
In case no basic block is provided a parameter-only set is expected to describe
the assumption.

The piecewise expressions that are generated by the SCEVAffinator sometimes
have a zero-dimensional domain (e.g., [p] -> { [] : p <= -129 or p >= 128 }),
which looks similar to a parameter-only domain, but is still a set domain.

This change adds an assert that checks that we always pass parameter domains to
addAssumptions if BB is empty to make mismatches here fail early.

We also change visitTruncExpr to always convert to parameter sets, if BB is
null. This change resolves http://llvm.org/PR30941

Another alternative to this change would have been to inspect all code to make
sure we directly generate in the SCEV affinator parameter sets in case of empty
domains. However, this would likely complicate the code which combines parameter
and non-parameter domains when constructing a statement domain. We might still
consider doing this at some point, but as this likely requires several non-local
changes this should probably be done as a separate refactoring.

Reported-by: Eli Friedman <efriedma at codeaurora.org>

Added:
    polly/trunk/test/ScopInfo/truncate-3.ll
Modified:
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/lib/Support/SCEVAffinator.cpp

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=286444&r1=286443&r2=286444&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Thu Nov 10 05:44:10 2016
@@ -3768,6 +3768,8 @@ void Scop::addAssumption(AssumptionKind
 
 void Scop::recordAssumption(AssumptionKind Kind, __isl_take isl_set *Set,
                             DebugLoc Loc, AssumptionSign Sign, BasicBlock *BB) {
+  assert((isl_set_is_params(Set) || BB) &&
+         "Assumptions without a basic block must be parameter sets");
   RecordedAssumptions.push_back({Kind, Sign, Set, Loc, BB});
 }
 

Modified: polly/trunk/lib/Support/SCEVAffinator.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/SCEVAffinator.cpp?rev=286444&r1=286443&r2=286444&view=diff
==============================================================================
--- polly/trunk/lib/Support/SCEVAffinator.cpp (original)
+++ polly/trunk/lib/Support/SCEVAffinator.cpp Thu Nov 10 05:44:10 2016
@@ -313,6 +313,13 @@ SCEVAffinator::visitTruncateExpr(const S
       isl_pw_aff_lt_set(isl_pw_aff_copy(OpPWAC.first), isl_pw_aff_neg(ExpPWA));
   auto *OutOfBoundsDom = isl_set_union(SmallerDom, GreaterDom);
   OpPWAC.second = isl_set_union(OpPWAC.second, isl_set_copy(OutOfBoundsDom));
+
+  if (!BB) {
+    assert(isl_set_dim(OutOfBoundsDom, isl_dim_set) == 0 &&
+           "Expected a zero dimensional set for non-basic-block domains");
+    OutOfBoundsDom = isl_set_params(OutOfBoundsDom);
+  }
+
   S->recordAssumption(UNSIGNED, OutOfBoundsDom, DebugLoc(), AS_RESTRICTION, BB);
 
   return OpPWAC;

Added: polly/trunk/test/ScopInfo/truncate-3.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/truncate-3.ll?rev=286444&view=auto
==============================================================================
--- polly/trunk/test/ScopInfo/truncate-3.ll (added)
+++ polly/trunk/test/ScopInfo/truncate-3.ll Thu Nov 10 05:44:10 2016
@@ -0,0 +1,26 @@
+; RUN: opt %loadPolly -polly-scops -pass-remarks-analysis="polly-scops" \
+; RUN:                -disable-output < %s 2>&1 | FileCheck %s
+
+; CHECK: Signed-unsigned restriction: [p] -> {  : p <= -129 or p >= 128 }
+
+; Verify that this test case does not crash when we try to model it.
+; At some point we tried to insert a restriction:
+;                                      [p] -> {  : p <= -129 or p >= 128 }
+; which resulted in a crash.
+
+target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
+
+define void @wobble(i16* %A, i32 %p) {
+bb:
+  %tmp1 = and i32 %p, 255
+  br label %bb4
+
+bb4:                                              ; preds = %bb4, %bb
+  %indvar = phi i16* [ %A, %bb ], [ %indvar.next, %bb4 ]
+  %val = load i16, i16* %indvar
+  %indvar.next = getelementptr inbounds i16, i16* %indvar, i32 %tmp1
+  br i1 false, label %bb4, label %bb9
+
+bb9:                                              ; preds = %bb4
+  ret void
+}




More information about the llvm-commits mailing list