[SCEVValidator] Loop exit values of loops before the SCoP are synthesizable.
authorMichael Kruse <llvm@meinersbur.de>
Wed, 26 Jul 2017 13:05:45 +0000 (13:05 +0000)
committerMichael Kruse <llvm@meinersbur.de>
Wed, 26 Jul 2017 13:05:45 +0000 (13:05 +0000)
 In the following loop:

   int i;
   for (i = 0; i < func(); i+=1)
     ;
SCoP:
   for (int j = 0; j<n; j+=1)
     S(i, j)

The value i is synthesizable in the SCoP that includes only the j-loop.
This is because i is fixed within the SCoP, it is irrelevant whether
it originates from another loop.

This fixes a strange case where a PHI was synthesiable in a SCoP,
but not its incoming value, triggering an assertion.

This should fix MultiSource/Applications/sgefa/sgefa of the
perf-x86_64-penryn-O3-polly-before-vectorizer-unprofitable buildbot.

llvm-svn: 309109

polly/lib/Support/SCEVValidator.cpp
polly/test/ScopDetect/index_from_unpredictable_loop.ll
polly/test/ScopDetect/index_from_unpredictable_loop2.ll [new file with mode: 0644]
polly/test/ScopInfo/unpredictable_nonscop_loop.ll [new file with mode: 0644]

index ccb91dd..f21b247 100644 (file)
@@ -506,10 +506,6 @@ public:
       if (AllowLoops)
         return true;
 
-      if (!Scope) {
-        HasInRegionDeps = true;
-        return false;
-      }
       auto *L = AddRec->getLoop();
       if (R->contains(L) && !L->contains(Scope)) {
         HasInRegionDeps = true;
index 17ee7f2..b9265ea 100644 (file)
@@ -42,8 +42,6 @@ for.end:
 ; AFFINE-NEXT:              [octets, p_1, p] -> { Stmt_if_then84[] : octets = 2 };
 ; AFFINE-NEXT:          Schedule :=
 ; AFFINE-NEXT:              [octets, p_1, p] -> { Stmt_if_then84[] -> [] };
-; AFFINE-NEXT:          ReadAccess :=  [Reduction Type: NONE] [Scalar: 1]
-; AFFINE-NEXT:              [octets, p_1, p] -> { Stmt_if_then84[] -> MemRef_indvars_iv[] };
 ; AFFINE-NEXT:          MustWriteAccess :=     [Reduction Type: NONE] [Scalar: 0]
 ; AFFINE-NEXT:              [octets, p_1, p] -> { Stmt_if_then84[] -> MemRef_input[1 + p] };
 ; AFFINE-NEXT:  }
diff --git a/polly/test/ScopDetect/index_from_unpredictable_loop2.ll b/polly/test/ScopDetect/index_from_unpredictable_loop2.ll
new file mode 100644 (file)
index 0000000..2020fdf
--- /dev/null
@@ -0,0 +1,86 @@
+; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s --check-prefix=AFFINE
+; RUN: opt %loadPolly -polly-scops -polly-allow-nonaffine -analyze < %s | FileCheck %s --check-prefix=NONAFFINE
+
+; The loop for.body => for.inc has an unpredictable iteration count could due to
+; the undef start value that it is compared to. Therefore the array element
+; %arrayidx101 that depends on that exit value cannot be affine.
+; Derived from test-suite/MultiSource/Benchmarks/BitBench/uuencode/uuencode.c
+
+define void @encode_line(i8* nocapture readonly %input, i32 %octets, i64 %p, i32 %n) {
+entry:
+  br label %outer.for
+
+outer.for:
+  %j = phi i32 [0, %entry], [%j.inc, %for.end]
+  %j.cmp = icmp slt i32 %j, %n
+  br i1 %j.cmp, label %for.body, label %exit
+
+
+
+for.body:
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ %p, %outer.for ]
+  %octets.addr.02 = phi i32 [ undef, %for.inc ], [ %octets, %outer.for ]
+  br i1 false, label %for.inc, label %if.else
+
+if.else:
+  %cond = icmp eq i32 %octets.addr.02, 2
+  br i1 %cond, label %if.then84, label %for.end
+
+if.then84:
+  %0 = add nsw i64 %indvars.iv, 1
+  %arrayidx101 = getelementptr inbounds i8, i8* %input, i64 %0
+  store i8 42, i8* %arrayidx101, align 1
+  br label %for.end
+
+for.inc:
+  %cmp = icmp sgt i32 %octets.addr.02, 3
+  %indvars.iv.next = add nsw i64 %indvars.iv, 3
+  br i1 %cmp, label %for.body, label %for.end
+
+
+
+for.end:
+  %j.inc = add nuw nsw i32 %j, 1
+  br label %outer.for
+
+exit:
+  br label %return
+
+return:
+  ret void
+}
+
+
+; AFFINE:       Region: %if.else---%for.end
+
+; AFFINE:       Statements {
+; AFFINE-NEXT:         Stmt_if_then84
+; AFFINE-NEXT:          Domain :=
+; AFFINE-NEXT:              [octets, p_1, p] -> { Stmt_if_then84[] : octets = 2 };
+; AFFINE-NEXT:          Schedule :=
+; AFFINE-NEXT:              [octets, p_1, p] -> { Stmt_if_then84[] -> [] };
+; AFFINE-NEXT:          MustWriteAccess :=     [Reduction Type: NONE] [Scalar: 0]
+; AFFINE-NEXT:              [octets, p_1, p] -> { Stmt_if_then84[] -> MemRef_input[1 + p] };
+; AFFINE-NEXT:  }
+
+
+; NONAFFINE:      Region: %outer.for---%return
+
+; NONAFFINE:      Statements {
+; NONAFFINE-NEXT:      Stmt_for_body
+; NONAFFINE-NEXT:         Domain :=
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_for_body[i0, 0] : 0 <= i0 < n };
+; NONAFFINE-NEXT:         Schedule :=
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_for_body[i0, i1] -> [i0, 0, 0] };
+; NONAFFINE-NEXT:         MustWriteAccess :=   [Reduction Type: NONE] [Scalar: 1]
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_for_body[i0, i1] -> MemRef_indvars_iv[] };
+; NONAFFINE-NEXT:      Stmt_if_then84
+; NONAFFINE-NEXT:         Domain :=
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_if_then84[i0] : octets = 2 and 0 <= i0 < n };
+; NONAFFINE-NEXT:         Schedule :=
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_if_then84[i0] -> [i0, 1, 0] };
+; NONAFFINE-NEXT:         ReadAccess :=        [Reduction Type: NONE] [Scalar: 1]
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_if_then84[i0] -> MemRef_indvars_iv[] };
+; NONAFFINE-NEXT:         MayWriteAccess :=    [Reduction Type: NONE] [Scalar: 0]
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_if_then84[i0] -> MemRef_input[o0] };
+; NONAFFINE-NEXT: }
diff --git a/polly/test/ScopInfo/unpredictable_nonscop_loop.ll b/polly/test/ScopInfo/unpredictable_nonscop_loop.ll
new file mode 100644 (file)
index 0000000..5452fac
--- /dev/null
@@ -0,0 +1,61 @@
+; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s -match-full-lines
+; Derived from test-suite/MultiSource/Applications/sgefa/blas.c
+;
+; The exit value of %i.0320 in land.rhs is not computable.
+; It is still synthesizable in %if.end13---%for.end170 because
+; %i.0320 is fixed within the SCoP and therefore just another parameter.
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @snrm2(i32 %n) local_unnamed_addr {
+entry:
+  br label %land.rhs
+
+land.rhs:                                         ; preds = %while.body, %entry
+  %i.0320 = phi i32 [ 0, %entry ], [ %inc, %while.body ]
+  br i1 undef, label %while.body, label %if.end13
+
+while.body:                                       ; preds = %land.rhs
+  %inc = add nuw nsw i32 %i.0320, 1
+  br label %land.rhs
+
+if.end13:                                         ; preds = %land.rhs
+  %i.4284 = add nsw i32 %i.0320, 1
+  %cmp131285 = icmp slt i32 %i.4284, %n
+  br i1 %cmp131285, label %for.body133.lr.ph, label %for.end170
+
+for.body133.lr.ph:                                ; preds = %if.end13
+  br label %for.body133
+
+for.body133:                                      ; preds = %for.body133, %for.body133.lr.ph
+  %i.4289 = phi i32 [ %i.4284, %for.body133.lr.ph ], [ %i.4, %for.body133 ]
+  %xmax.2287 = phi float [ undef, %for.body133.lr.ph ], [ undef, %for.body133 ]
+  %i.4 = add nsw i32 %i.4289, 1
+  %exitcond = icmp eq i32 %i.4, %n
+  br i1 %exitcond, label %for.end170, label %for.body133
+
+for.end170:                                       ; preds = %for.body133, %if.end13
+  ret void
+}
+
+
+; CHECK: Region: %if.end13---%for.end170
+
+; CHECK:      Statements {
+; CHECK-NEXT:     Stmt_for_body133_lr_ph
+; CHECK-NEXT:         Domain :=
+; CHECK-NEXT:             [p_0, n] -> { Stmt_for_body133_lr_ph[] : n >= 2 + p_0 };
+; CHECK-NEXT:         Schedule :=
+; CHECK-NEXT:             [p_0, n] -> { Stmt_for_body133_lr_ph[] -> [0, 0] };
+; CHECK-NEXT:         MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 1]
+; CHECK-NEXT:             [p_0, n] -> { Stmt_for_body133_lr_ph[] -> MemRef_xmax_2287__phi[] };
+; CHECK-NEXT:     Stmt_for_body133
+; CHECK-NEXT:         Domain :=
+; CHECK-NEXT:             [p_0, n] -> { Stmt_for_body133[i0] : 0 <= i0 <= -2 - p_0 + n };
+; CHECK-NEXT:         Schedule :=
+; CHECK-NEXT:             [p_0, n] -> { Stmt_for_body133[i0] -> [1, i0] };
+; CHECK-NEXT:         MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 1]
+; CHECK-NEXT:             [p_0, n] -> { Stmt_for_body133[i0] -> MemRef_xmax_2287__phi[] };
+; CHECK-NEXT:         ReadAccess :=       [Reduction Type: NONE] [Scalar: 1]
+; CHECK-NEXT:             [p_0, n] -> { Stmt_for_body133[i0] -> MemRef_xmax_2287__phi[] };
+; CHECK-NEXT: }