[polly] r309109 - [SCEVValidator] Loop exit values of loops before the SCoP are synthesizable.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 26 06:05:45 PDT 2017


Author: meinersbur
Date: Wed Jul 26 06:05:45 2017
New Revision: 309109

URL: http://llvm.org/viewvc/llvm-project?rev=309109&view=rev
Log:
[SCEVValidator] Loop exit values of loops before the SCoP are synthesizable.

 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.

Added:
    polly/trunk/test/ScopDetect/index_from_unpredictable_loop2.ll
      - copied, changed from r309039, polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll
    polly/trunk/test/ScopInfo/unpredictable_nonscop_loop.ll
Modified:
    polly/trunk/lib/Support/SCEVValidator.cpp
    polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll

Modified: polly/trunk/lib/Support/SCEVValidator.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/SCEVValidator.cpp?rev=309109&r1=309108&r2=309109&view=diff
==============================================================================
--- polly/trunk/lib/Support/SCEVValidator.cpp (original)
+++ polly/trunk/lib/Support/SCEVValidator.cpp Wed Jul 26 06:05:45 2017
@@ -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;

Modified: polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll?rev=309109&r1=309108&r2=309109&view=diff
==============================================================================
--- polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll (original)
+++ polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll Wed Jul 26 06:05:45 2017
@@ -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:  }

Copied: polly/trunk/test/ScopDetect/index_from_unpredictable_loop2.ll (from r309039, polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll)
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopDetect/index_from_unpredictable_loop2.ll?p2=polly/trunk/test/ScopDetect/index_from_unpredictable_loop2.ll&p1=polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll&r1=309039&r2=309109&rev=309109&view=diff
==============================================================================
--- polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll (original)
+++ polly/trunk/test/ScopDetect/index_from_unpredictable_loop2.ll Wed Jul 26 06:05:45 2017
@@ -6,13 +6,20 @@
 ; %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) {
+define void @encode_line(i8* nocapture readonly %input, i32 %octets, i64 %p, i32 %n) {
 entry:
-  br i1 undef, label %for.body, label %for.end
+  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, %entry ]
-  %octets.addr.02 = phi i32 [ undef, %for.inc ], [ %octets, %entry ]
+  %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:
@@ -30,10 +37,20 @@ for.inc:
   %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 {
@@ -42,29 +59,28 @@ 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:  }
 
-; NONAFFINE:      Region: %for.body---%for.end
+
+; NONAFFINE:      Region: %outer.for---%return
 
 ; NONAFFINE:      Statements {
 ; NONAFFINE-NEXT: 	Stmt_for_body
 ; NONAFFINE-NEXT:         Domain :=
-; NONAFFINE-NEXT:             [octets] -> { Stmt_for_body[0] };
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_for_body[i0, 0] : 0 <= i0 < n };
 ; NONAFFINE-NEXT:         Schedule :=
-; NONAFFINE-NEXT:             [octets] -> { Stmt_for_body[i0] -> [0, 0] };
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_for_body[i0, i1] -> [i0, 0, 0] };
 ; NONAFFINE-NEXT:         MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 1]
-; NONAFFINE-NEXT:             [octets] -> { Stmt_for_body[i0] -> MemRef_indvars_iv[] };
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_for_body[i0, i1] -> MemRef_indvars_iv[] };
 ; NONAFFINE-NEXT: 	Stmt_if_then84
 ; NONAFFINE-NEXT:         Domain :=
-; NONAFFINE-NEXT:             [octets] -> { Stmt_if_then84[] : octets = 2 };
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_if_then84[i0] : octets = 2 and 0 <= i0 < n };
 ; NONAFFINE-NEXT:         Schedule :=
-; NONAFFINE-NEXT:             [octets] -> { Stmt_if_then84[] -> [1, 0] };
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_if_then84[i0] -> [i0, 1, 0] };
 ; NONAFFINE-NEXT:         ReadAccess :=	[Reduction Type: NONE] [Scalar: 1]
-; NONAFFINE-NEXT:             [octets] -> { Stmt_if_then84[] -> MemRef_indvars_iv[] };
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_if_then84[i0] -> MemRef_indvars_iv[] };
 ; NONAFFINE-NEXT:         MayWriteAccess :=	[Reduction Type: NONE] [Scalar: 0]
-; NONAFFINE-NEXT:             [octets] -> { Stmt_if_then84[] -> MemRef_input[o0] };
+; NONAFFINE-NEXT:             [n, octets] -> { Stmt_if_then84[i0] -> MemRef_input[o0] };
 ; NONAFFINE-NEXT: }

Added: polly/trunk/test/ScopInfo/unpredictable_nonscop_loop.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/unpredictable_nonscop_loop.ll?rev=309109&view=auto
==============================================================================
--- polly/trunk/test/ScopInfo/unpredictable_nonscop_loop.ll (added)
+++ polly/trunk/test/ScopInfo/unpredictable_nonscop_loop.ll Wed Jul 26 06:05:45 2017
@@ -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: }




More information about the llvm-commits mailing list