[polly] r265286 - Do not allow to complex branch conditions

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 4 00:59:41 PDT 2016


Author: jdoerfert
Date: Mon Apr  4 02:59:41 2016
New Revision: 265286

URL: http://llvm.org/viewvc/llvm-project?rev=265286&view=rev
Log:
Do not allow to complex branch conditions

  Even before we build the domain the branch condition can become very
  complex, especially if we have to build the complement of a lot of
  equality constraints. With this patch we bail if the branch condition
  has a lot of basic sets and parameters.

  After this patch we now successfully compile
    External/SPEC/CINT2000/186_crafty/186_crafty
  with "-polly-process-unprofitable -polly-position=before-vectorizer".

Added:
    polly/trunk/test/ScopInfo/complex-condition.ll
Modified:
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/test/ScopInfo/complex-successor-structure-2.ll
    polly/trunk/test/ScopInfo/user_provided_assumptions.ll

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=265286&r1=265285&r2=265286&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Mon Apr  4 02:59:41 2016
@@ -1240,15 +1240,23 @@ buildConditionSets(Scop &S, Value *Condi
   // under which @p Condition is true/false.
   if (!TI)
     ConsequenceCondSet = isl_set_params(ConsequenceCondSet);
-
   assert(ConsequenceCondSet);
-  isl_set *AlternativeCondSet =
-      isl_set_complement(isl_set_copy(ConsequenceCondSet));
+  ConsequenceCondSet = isl_set_coalesce(
+      isl_set_intersect(ConsequenceCondSet, isl_set_copy(Domain)));
+
+  isl_set *AlternativeCondSet;
+  unsigned NumParams = isl_set_n_param(ConsequenceCondSet);
+  unsigned NumBasicSets = isl_set_n_basic_set(ConsequenceCondSet);
+  if (NumBasicSets + NumParams < MaxConjunctsInDomain) {
+    AlternativeCondSet = isl_set_subtract(isl_set_copy(Domain),
+                                          isl_set_copy(ConsequenceCondSet));
+  } else {
+    S.invalidate(COMPLEXITY, TI ? TI->getDebugLoc() : DebugLoc());
+    AlternativeCondSet = isl_set_empty(isl_set_get_space(ConsequenceCondSet));
+  }
 
-  ConditionSets.push_back(isl_set_coalesce(
-      isl_set_intersect(ConsequenceCondSet, isl_set_copy(Domain))));
-  ConditionSets.push_back(isl_set_coalesce(
-      isl_set_intersect(AlternativeCondSet, isl_set_copy(Domain))));
+  ConditionSets.push_back(ConsequenceCondSet);
+  ConditionSets.push_back(isl_set_coalesce(AlternativeCondSet));
 }
 
 /// @brief Build the conditions sets for the terminator @p TI in the @p Domain.
@@ -2390,7 +2398,7 @@ bool Scop::buildDomainsWithBranchConstra
 
       // Check if the maximal number of domain conjuncts was reached.
       // In case this happens we will clean up and bail.
-      if (isl_set_n_basic_set(SuccDomain) <= MaxConjunctsInDomain)
+      if (isl_set_n_basic_set(SuccDomain) < MaxConjunctsInDomain)
         continue;
 
       invalidate(COMPLEXITY, DebugLoc());

Added: polly/trunk/test/ScopInfo/complex-condition.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/complex-condition.ll?rev=265286&view=auto
==============================================================================
--- polly/trunk/test/ScopInfo/complex-condition.ll (added)
+++ polly/trunk/test/ScopInfo/complex-condition.ll Mon Apr  4 02:59:41 2016
@@ -0,0 +1,145 @@
+; RUN: opt %loadPolly -pass-remarks-analysis="polly-scops" -polly-scops \
+; RUN:     < %s 2>&1 | FileCheck %s
+;
+; CHECK: Low complexity assumption: {  : 1 = 0 }
+;
+; The IR is a modified version of the following C:
+;
+;    void f(int *A) {
+;    Begin:
+;      if (A[0] == 1 | A[1] == 1 | A[2] == 1 | A[3] == 1 | A[4] == 1 | A[5] == 1 |
+;          A[6] == 1 | A[7] == 1 | A[8] == 1 | A[9] == 1 | A[10] == 1 | A[11] == 1 |
+;          A[12] == 1 | A[13] == 1 | A[14] == 1 | A[15] == 1 | A[16] == 1 |
+;          A[17] == 1 | A[18] == 1 | A[19] == 1 | A[20] == 1 | A[21] == 1 |
+;          A[22] == 1 | A[23]) {
+;        A[-1]++;
+;      } else {
+;        A[-1]--;
+;      }
+;    End:
+;      return;
+;    }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @f(i32* %A) {
+entry:
+  br label %Begin
+
+Begin:                                            ; preds = %entry
+  %tmp = load i32, i32* %A, align 4
+  %cmp = icmp eq i32 %tmp, 1
+  %arrayidx1 = getelementptr inbounds i32, i32* %A, i64 1
+  %tmp1 = load i32, i32* %arrayidx1, align 4
+  %cmp2 = icmp eq i32 %tmp1, 1
+  %or = or i1 %cmp, %cmp2
+  %arrayidx4 = getelementptr inbounds i32, i32* %A, i64 2
+  %tmp2 = load i32, i32* %arrayidx4, align 4
+  %cmp5 = icmp eq i32 %tmp2, 1
+  %or7 = or i1 %or, %cmp5
+  %arrayidx8 = getelementptr inbounds i32, i32* %A, i64 3
+  %tmp3 = load i32, i32* %arrayidx8, align 4
+  %cmp9 = icmp eq i32 %tmp3, 1
+  %or11 = or i1 %or7, %cmp9
+  %arrayidx12 = getelementptr inbounds i32, i32* %A, i64 4
+  %tmp4 = load i32, i32* %arrayidx12, align 4
+  %cmp13 = icmp eq i32 %tmp4, 1
+  %or15 = or i1 %or11, %cmp13
+  %arrayidx16 = getelementptr inbounds i32, i32* %A, i64 5
+  %tmp5 = load i32, i32* %arrayidx16, align 4
+  %cmp17 = icmp eq i32 %tmp5, 1
+  %or19 = or i1 %or15, %cmp17
+  %arrayidx20 = getelementptr inbounds i32, i32* %A, i64 6
+  %tmp6 = load i32, i32* %arrayidx20, align 4
+  %cmp21 = icmp eq i32 %tmp6, 1
+  %or23 = or i1 %or19, %cmp21
+  %arrayidx24 = getelementptr inbounds i32, i32* %A, i64 7
+  %tmp7 = load i32, i32* %arrayidx24, align 4
+  %cmp25 = icmp eq i32 %tmp7, 1
+  %or27 = or i1 %or23, %cmp25
+  %arrayidx28 = getelementptr inbounds i32, i32* %A, i64 8
+  %tmp8 = load i32, i32* %arrayidx28, align 4
+  %cmp29 = icmp eq i32 %tmp8, 1
+  %or31 = or i1 %or27, %cmp29
+  %arrayidx32 = getelementptr inbounds i32, i32* %A, i64 9
+  %tmp9 = load i32, i32* %arrayidx32, align 4
+  %cmp33 = icmp eq i32 %tmp9, 1
+  %or35 = or i1 %or31, %cmp33
+  %arrayidx36 = getelementptr inbounds i32, i32* %A, i64 10
+  %tmp10 = load i32, i32* %arrayidx36, align 4
+  %cmp37 = icmp eq i32 %tmp10, 1
+  %or39 = or i1 %or35, %cmp37
+  %arrayidx40 = getelementptr inbounds i32, i32* %A, i64 11
+  %tmp11 = load i32, i32* %arrayidx40, align 4
+  %cmp41 = icmp eq i32 %tmp11, 1
+  %or43 = or i1 %or39, %cmp41
+  %arrayidx44 = getelementptr inbounds i32, i32* %A, i64 12
+  %tmp12 = load i32, i32* %arrayidx44, align 4
+  %cmp45 = icmp eq i32 %tmp12, 1
+  %or47 = or i1 %or43, %cmp45
+  %arrayidx48 = getelementptr inbounds i32, i32* %A, i64 13
+  %tmp13 = load i32, i32* %arrayidx48, align 4
+  %cmp49 = icmp eq i32 %tmp13, 1
+  %or51 = or i1 %or47, %cmp49
+  %arrayidx52 = getelementptr inbounds i32, i32* %A, i64 14
+  %tmp14 = load i32, i32* %arrayidx52, align 4
+  %cmp53 = icmp eq i32 %tmp14, 1
+  %or55 = or i1 %or51, %cmp53
+  %arrayidx56 = getelementptr inbounds i32, i32* %A, i64 15
+  %tmp15 = load i32, i32* %arrayidx56, align 4
+  %cmp57 = icmp eq i32 %tmp15, 1
+  %or59 = or i1 %or55, %cmp57
+  %arrayidx60 = getelementptr inbounds i32, i32* %A, i64 16
+  %tmp16 = load i32, i32* %arrayidx60, align 4
+  %cmp61 = icmp eq i32 %tmp16, 1
+  %or63 = or i1 %or59, %cmp61
+  %arrayidx64 = getelementptr inbounds i32, i32* %A, i64 17
+  %tmp17 = load i32, i32* %arrayidx64, align 4
+  %cmp65 = icmp eq i32 %tmp17, 1
+  %or67 = or i1 %or63, %cmp65
+  %arrayidx68 = getelementptr inbounds i32, i32* %A, i64 18
+  %tmp18 = load i32, i32* %arrayidx68, align 4
+  %cmp69 = icmp eq i32 %tmp18, 1
+  %or71 = or i1 %or67, %cmp69
+  %arrayidx72 = getelementptr inbounds i32, i32* %A, i64 19
+  %tmp19 = load i32, i32* %arrayidx72, align 4
+  %cmp73 = icmp eq i32 %tmp19, 1
+  %or75 = or i1 %or71, %cmp73
+  %arrayidx76 = getelementptr inbounds i32, i32* %A, i64 20
+  %tmp20 = load i32, i32* %arrayidx76, align 4
+  %cmp77 = icmp eq i32 %tmp20, 1
+  %or79 = or i1 %or75, %cmp77
+  %arrayidx80 = getelementptr inbounds i32, i32* %A, i64 21
+  %tmp21 = load i32, i32* %arrayidx80, align 4
+  %cmp81 = icmp eq i32 %tmp21, 1
+  %or83 = or i1 %or79, %cmp81
+  %arrayidx84 = getelementptr inbounds i32, i32* %A, i64 22
+  %tmp22 = load i32, i32* %arrayidx84, align 4
+  %cmp85 = icmp eq i32 %tmp22, 1
+  %or87 = or i1 %or83, %cmp85
+  %arrayidx88 = getelementptr inbounds i32, i32* %A, i64 23
+  %tmp23 = load i32, i32* %arrayidx88, align 4
+  %cmp88 = icmp eq i32 %tmp23, 1
+  %or89 = or i1 %or87, %cmp88
+  br i1 %or89, label %if.else, label %if.then
+
+if.then:                                          ; preds = %Begin
+  %arrayidx90 = getelementptr inbounds i32, i32* %A, i64 -1
+  %tmp24 = load i32, i32* %arrayidx90, align 4
+  %inc = add nsw i32 %tmp24, 1
+  store i32 %inc, i32* %arrayidx90, align 4
+  br label %if.end
+
+if.else:                                          ; preds = %Begin
+  %arrayidx91 = getelementptr inbounds i32, i32* %A, i64 -1
+  %tmp25 = load i32, i32* %arrayidx91, align 4
+  %dec = add nsw i32 %tmp25, -1
+  store i32 %dec, i32* %arrayidx91, align 4
+  br label %if.end
+
+if.end:                                           ; preds = %if.else, %if.then
+  br label %End
+
+End:                                              ; preds = %if.end
+  ret void
+}

Modified: polly/trunk/test/ScopInfo/complex-successor-structure-2.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/complex-successor-structure-2.ll?rev=265286&r1=265285&r2=265286&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/complex-successor-structure-2.ll (original)
+++ polly/trunk/test/ScopInfo/complex-successor-structure-2.ll Mon Apr  4 02:59:41 2016
@@ -4,7 +4,7 @@
 ; We build a scop for the region for.body->B13. The CFG is of the following
 ; form and the branch conditions are build from "smax" SCEVs. However, in
 ; contrast to complex-success-structure.ll the smax constraints do not grow
-; anymore after B4. This will keep the condition construction bounded.
+; anymore after B3. This will keep the condition construction bounded.
 ; Since we propagate the domains from one B(X) to the B(X+1) we can also keep
 ; the domains simple. We will bail anyway due to invalid required invariant
 ; loads.
@@ -443,7 +443,7 @@ A4:
 
 B4:                                       ; preds = %A4, %B3
   %46 = phi i16 [ %add84.3, %A4 ], [ %45, %B3 ]
-  %add84.4 = add i16 %46, 128
+  %add84.4 = add i16 %44, 128
   %arrayidx74.5 = getelementptr inbounds i16, i16* %Output, i32 5
   %47 = load i16, i16* %arrayidx74.5, align 2
   %cmp77.5 = icmp slt i16 %47, %add84.4
@@ -455,7 +455,7 @@ A5:
 
 B5:                                       ; preds = %A5, %B4
   %48 = phi i16 [ %add84.4, %A5 ], [ %47, %B4 ]
-  %add84.5 = add i16 %46, 128
+  %add84.5 = add i16 %44, 128
   %arrayidx74.6 = getelementptr inbounds i16, i16* %Output, i32 6
   %49 = load i16, i16* %arrayidx74.6, align 2
   %cmp77.6 = icmp slt i16 %49, %add84.5
@@ -467,7 +467,7 @@ A6:
 
 B6:                                       ; preds = %A6, %B5
   %50 = phi i16 [ %add84.5, %A6 ], [ %49, %B5 ]
-  %add84.6 = add i16 %46, 128
+  %add84.6 = add i16 %44, 128
   %arrayidx74.7 = getelementptr inbounds i16, i16* %Output, i32 7
   %51 = load i16, i16* %arrayidx74.7, align 2
   %cmp77.7 = icmp slt i16 %51, %add84.6
@@ -479,7 +479,7 @@ A7:
 
 B7:                                       ; preds = %A7, %B6
   %52 = phi i16 [ %add84.6, %A7 ], [ %51, %B6 ]
-  %add84.7 = add i16 %46, 128
+  %add84.7 = add i16 %44, 128
   %arrayidx74.8 = getelementptr inbounds i16, i16* %Output, i32 8
   %53 = load i16, i16* %arrayidx74.8, align 2
   %cmp77.8 = icmp slt i16 %53, %add84.7
@@ -491,7 +491,7 @@ A8:
 
 B8:                                       ; preds = %A8, %B7
   %54 = phi i16 [ %add84.7, %A8 ], [ %53, %B7 ]
-  %add84.8 = add i16 %46, 128
+  %add84.8 = add i16 %44, 128
   %cmp77.9 = icmp slt i16 %.reload, %add84.8
   br i1 %cmp77.9, label %A9, label %B9
 
@@ -502,7 +502,7 @@ A9:
 
 B9:                                       ; preds = %A9, %B8
   %55 = phi i16 [ %add84.8, %A9 ], [ %.reload, %B8 ]
-  %add84.9 = add i16 %46, 128
+  %add84.9 = add i16 %44, 128
   %cmp77.10 = icmp slt i16 %.reload151, %add84.9
   br i1 %cmp77.10, label %A10, label %B10
 
@@ -513,7 +513,7 @@ A10:
 
 B10:                                      ; preds = %A10, %B9
   %56 = phi i16 [ %add84.9, %A10 ], [ %.reload151, %B9 ]
-  %add84.10 = add i16 %46, 128
+  %add84.10 = add i16 %44, 128
   %cmp77.11 = icmp slt i16 %.reload153, %add84.10
   br i1 %cmp77.11, label %A11, label %B11
 
@@ -524,7 +524,7 @@ A11:
 
 B11:                                      ; preds = %A11, %B10
   %57 = phi i16 [ %add84.10, %A11 ], [ %.reload153, %B10 ]
-  %add84.11 = add i16 %46, 128
+  %add84.11 = add i16 %44, 128
   %cmp77.12 = icmp slt i16 %.reload155, %add84.11
   br i1 %cmp77.12, label %A12, label %B13
 

Modified: polly/trunk/test/ScopInfo/user_provided_assumptions.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/user_provided_assumptions.ll?rev=265286&r1=265285&r2=265286&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/user_provided_assumptions.ll (original)
+++ polly/trunk/test/ScopInfo/user_provided_assumptions.ll Mon Apr  4 02:59:41 2016
@@ -5,7 +5,7 @@
 ; CHECK-NEXT: remark: <unknown>:0:0: Use user assumption: [M, N] -> {  : N <= 2147483647 - M }
 ; CHECK-NEXT: remark: <unknown>:0:0: Use user assumption: [M, N] -> {  : -2147483648 - M <= N <= 2147483647 - M }
 ; CHECK-NEXT: remark: <unknown>:0:0: Use user assumption: [M, N, Debug] -> {  : Debug = 0 and 0 < M <= 100 and -2147483648 - M <= N <= 2147483647 - M }
-; CHECK-NEXT: remark: <unknown>:0:0: Use user assumption: [M, N, Debug] -> {  : Debug = 0 and 0 < M <= 100 and N > 0 and -2147483648 - M <= N <= 2147483647 - M }
+; CHECK-NEXT: remark: <unknown>:0:0: Use user assumption: [M, N, Debug] -> { : Debug = 0 and 0 < M <= 100 and 0 < N <= 2147483647 - M }
 ; CHECK-NEXT: remark: <unknown>:0:0: SCoP ends here.
 
 ; SCOP:      Context:




More information about the llvm-commits mailing list