[polly] r249139 - [FIX] Do not hoist from inside a non-affine subregion

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 07:51:00 PDT 2015


Author: jdoerfert
Date: Fri Oct  2 09:51:00 2015
New Revision: 249139

URL: http://llvm.org/viewvc/llvm-project?rev=249139&view=rev
Log:
[FIX] Do not hoist from inside a non-affine subregion

  We have to skip accesses in non-affine subregions during hoisting as
  they might not be executed under the same condition as the entry of
  the non-affine subregion.


Added:
    polly/trunk/test/ScopInfo/NonAffine/invariant_loads_dependent_in_non_affine_region.ll
Modified:
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/test/Isl/CodeGen/non-affine-phi-node-expansion.ll

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=249139&r1=249138&r2=249139&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Fri Oct  2 09:51:00 2015
@@ -2396,6 +2396,8 @@ void Scop::hoistInvariantLoads() {
     //       zero iterators, are by construction invariant, though we
     //       currently "hoist" them anyway.
 
+    BasicBlock *BB = Stmt.isBlockStmt() ? Stmt.getBasicBlock()
+                                        : Stmt.getRegion()->getEntry();
     isl_set *Domain = Stmt.getDomain();
     MemoryAccessList InvMAs;
 
@@ -2403,6 +2405,11 @@ void Scop::hoistInvariantLoads() {
       if (MA->isImplicit() || MA->isWrite() || !MA->isAffine())
         continue;
 
+      // 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 != MA->getAccessInstruction()->getParent())
+        continue;
+
       isl_map *AccessRelation = MA->getAccessRelation();
       if (isl_map_involves_dims(AccessRelation, isl_dim_in, 0,
                                 Stmt.getNumIterators())) {

Modified: polly/trunk/test/Isl/CodeGen/non-affine-phi-node-expansion.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/non-affine-phi-node-expansion.ll?rev=249139&r1=249138&r2=249139&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/non-affine-phi-node-expansion.ll (original)
+++ polly/trunk/test/Isl/CodeGen/non-affine-phi-node-expansion.ll Fri Oct  2 09:51:00 2015
@@ -4,10 +4,9 @@ target datalayout = "e-m:e-i64:64-f80:12
 
 %struct.wombat = type {[4 x i32]}
 
-; CHECK:      polly.preload.begin:
-; CHECK-NEXT:   %polly.access.B = getelementptr i32, i32* %B, i64 0
-; CHECK-NEXT:   %polly.access.B.load = load i32, i32* %polly.access.B
-; CHECK-NOT:    %polly.access.B.load = load i32, i32* %polly.access.B
+; CHECK-NOT:  polly.preload.begin:
+; CHECK-NOT::   %polly.access.B
+; CHECK-NOT:    %polly.access.B.load
 
 ; CHECK: polly.stmt.bb3.entry:                             ; preds = %polly.start
 ; CHECK:   br label %polly.stmt.bb3

Added: polly/trunk/test/ScopInfo/NonAffine/invariant_loads_dependent_in_non_affine_region.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/NonAffine/invariant_loads_dependent_in_non_affine_region.ll?rev=249139&view=auto
==============================================================================
--- polly/trunk/test/ScopInfo/NonAffine/invariant_loads_dependent_in_non_affine_region.ll (added)
+++ polly/trunk/test/ScopInfo/NonAffine/invariant_loads_dependent_in_non_affine_region.ll Fri Oct  2 09:51:00 2015
@@ -0,0 +1,57 @@
+; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s
+;
+;    void f(int *A, int *B, int *C) {
+;      for (int i = 0; i < 1000; i++)
+;        if (A[i] == *B)
+;          A[i] = *C;
+;    }
+;
+; Check that only the access to *B is hoisted but not the one to *C.
+;
+; CHECK: Invariant Accesses: {
+; CHECK:     ReadAccess := [Reduction Type: NONE] [Scalar: 0]
+; CHECK:         { Stmt_for_body__TO__if_end[i0] -> MemRef_B[0] };
+; CHECK:     Execution Context: {  :  }
+; CHECK: }
+;
+; CHECK: Statements {
+; CHECK:   Stmt_for_body__TO__if_end
+; CHECK:     ReadAccess := [Reduction Type: NONE] [Scalar: 0]
+; CHECK:         { Stmt_for_body__TO__if_end[i0] -> MemRef_C[0] };
+; CHECK: }
+
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @f(i32* %A, i32* %B, i32* %C) {
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
+  %exitcond = icmp ne i64 %indvars.iv, 1000
+  br i1 %exitcond, label %for.body, label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
+  %tmp = load i32, i32* %arrayidx, align 4
+  %tmp1 = load i32, i32* %B, align 4
+  %cmp1 = icmp eq i32 %tmp, %tmp1
+  br i1 %cmp1, label %if.then, label %if.end
+
+if.then:                                          ; preds = %for.body
+  %tmp2 = load i32, i32* %C, align 4
+  %arrayidx3 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
+  store i32 %tmp2, i32* %arrayidx3, align 4
+  br label %if.end
+
+if.end:                                           ; preds = %if.then, %for.body
+  br label %for.inc
+
+for.inc:                                          ; preds = %if.end
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  br label %for.cond
+
+for.end:                                          ; preds = %for.cond
+  ret void
+}




More information about the llvm-commits mailing list