[polly] r249276 - Remove non-executed statements during SCoP simplifcation

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 4 08:00:05 PDT 2015


Author: jdoerfert
Date: Sun Oct  4 10:00:05 2015
New Revision: 249276

URL: http://llvm.org/viewvc/llvm-project?rev=249276&view=rev
Log:
Remove non-executed statements during SCoP simplifcation

  A statement with an empty domain complicates the invariant load
  hoisting and does not help any subsequent analysis or transformation.
  In fact it might introduce parameter dimensions or increase the
  schedule dimensionality. To this end, we remove statements with an
  empty domain early in the SCoP simplification.


Added:
    polly/trunk/test/Isl/CodeGen/variant_load_empty_domain.ll
    polly/trunk/test/ScopInfo/variant_load_empty_domain.ll
Modified:
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/test/ScopInfo/cond_constant_in_loop.ll
    polly/trunk/test/ScopInfo/switch-4.ll
    polly/trunk/test/ScopInfo/switch-5.ll

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=249276&r1=249275&r2=249276&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Sun Oct  4 10:00:05 2015
@@ -2373,7 +2373,10 @@ void Scop::simplifySCoP(bool RemoveIgnor
                          ? Stmt.getRegion()->getNode()
                          : getRegion().getBBNode(Stmt.getBasicBlock());
 
-    if (StmtIt->isEmpty() || (RemoveIgnoredStmts && isIgnored(RN))) {
+    if (StmtIt->isEmpty() ||
+        isl_set_is_empty(DomainMap[getRegionNodeBasicBlock(RN)]) ||
+        (RemoveIgnoredStmts && isIgnored(RN))) {
+
       // Remove the statement because it is unnecessary.
       if (Stmt.isRegionStmt())
         for (BasicBlock *BB : Stmt.getRegion()->blocks())

Added: polly/trunk/test/Isl/CodeGen/variant_load_empty_domain.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/variant_load_empty_domain.ll?rev=249276&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/variant_load_empty_domain.ll (added)
+++ polly/trunk/test/Isl/CodeGen/variant_load_empty_domain.ll Sun Oct  4 10:00:05 2015
@@ -0,0 +1,47 @@
+; RUN: opt %loadPolly -polly-codegen -polly-detect-unprofitable -analyze < %s
+;
+;
+;    void f(int *A) {
+;      for (int i = 1; i < 10; i++) {
+;        A[i]++;
+;        if (i > 10)
+;          A[i] += A[0];
+;      }
+;    }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @f(i32* %A) {
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 1, %entry ]
+  %exitcond = icmp ne i64 %indvars.iv, 10
+  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
+  %inc = add nsw i32 %tmp, 1
+  store i32 %inc, i32* %arrayidx, align 4
+  br i1 false, label %if.then, label %if.end
+
+if.then:                                          ; preds = %for.body
+  %tmp1 = load i32, i32* %A, align 4
+  %arrayidx4 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
+  %tmp2 = load i32, i32* %arrayidx4, align 4
+  %add = add nsw i32 %tmp2, %tmp1
+  store i32 %add, i32* %arrayidx4, 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
+}

Modified: polly/trunk/test/ScopInfo/cond_constant_in_loop.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/cond_constant_in_loop.ll?rev=249276&r1=249275&r2=249276&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/cond_constant_in_loop.ll (original)
+++ polly/trunk/test/ScopInfo/cond_constant_in_loop.ll Sun Oct  4 10:00:05 2015
@@ -43,9 +43,7 @@ return:
   ret void
 }
 
-; CHECK: Stmt_bb1
-; CHECK:   Domain :=
-; CHECK:     [M, N] -> { Stmt_bb1[i0] : i0 >= 0 and i0 <= -1 + M };
-; CHECK: Stmt_bb2
-; CHECK:   Domain :=
-; CHECK:     [M, N] -> { Stmt_bb2[i0] : 1 = 0 };
+; CHECK:     Stmt_bb1
+; CHECK:       Domain :=
+; CHECK:         [M] -> { Stmt_bb1[i0] : i0 >= 0 and i0 <= -1 + M };
+; CHECK-NOT: Stmt_bb2

Modified: polly/trunk/test/ScopInfo/switch-4.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/switch-4.ll?rev=249276&r1=249275&r2=249276&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/switch-4.ll (original)
+++ polly/trunk/test/ScopInfo/switch-4.ll Sun Oct  4 10:00:05 2015
@@ -22,9 +22,7 @@
 ;    }
 ;
 ; CHECK:    Statements {
-; CHECK:      Stmt_sw_default
-; CHECK:            Domain :=
-; CHECK:                [N] -> { Stmt_sw_default[i0] : 1 = 0 };
+; CHECK-NOT:  Stmt_sw_default
 ; CHECK:      Stmt_sw_bb
 ; CHECK:            Domain :=
 ; CHECK:                [N] -> { Stmt_sw_bb[i0] : exists (e0 = floor((i0)/4): 4e0 = i0 and i0 >= 0 and i0 <= -1 + N) };

Modified: polly/trunk/test/ScopInfo/switch-5.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/switch-5.ll?rev=249276&r1=249275&r2=249276&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/switch-5.ll (original)
+++ polly/trunk/test/ScopInfo/switch-5.ll Sun Oct  4 10:00:05 2015
@@ -19,10 +19,8 @@
 ; CHECK:            Domain :=
 ; CHECK:                [N] -> { Stmt_for_body[0] : N >= 1 };
 ; CHECK:            Schedule :=
-; CHECK:                [N] -> { Stmt_for_body[i0] -> [0, 0] };
-; CHECK:      Stmt_sw_bb
-; CHECK:            Domain :=
-; CHECK:                [N] -> { Stmt_sw_bb[i0] : 1 = 0 };
+; CHECK:                [N] -> { Stmt_for_body[i0] -> [0] };
+; CHECK-NOT:  Stmt_sw_bb
 ; CHECK:    }
 ;
 ; AST:    if (N >= 1)

Added: polly/trunk/test/ScopInfo/variant_load_empty_domain.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/variant_load_empty_domain.ll?rev=249276&view=auto
==============================================================================
--- polly/trunk/test/ScopInfo/variant_load_empty_domain.ll (added)
+++ polly/trunk/test/ScopInfo/variant_load_empty_domain.ll Sun Oct  4 10:00:05 2015
@@ -0,0 +1,52 @@
+; RUN: opt %loadPolly -polly-scops -polly-detect-unprofitable -analyze < %s | FileCheck %s
+;
+; CHECK:      Invariant Accesses: {
+; CHECK-NEXT: }
+;
+; CHECK-NOT: Stmt_if_then
+;
+;
+;    void f(int *A) {
+;      for (int i = 1; i < 10; i++) {
+;        A[i]++;
+;        if (i > 10)
+;          A[i] += A[0];
+;      }
+;    }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @f(i32* %A) {
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 1, %entry ]
+  %exitcond = icmp ne i64 %indvars.iv, 10
+  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
+  %inc = add nsw i32 %tmp, 1
+  store i32 %inc, i32* %arrayidx, align 4
+  br i1 false, label %if.then, label %if.end
+
+if.then:                                          ; preds = %for.body
+  %tmp1 = load i32, i32* %A, align 4
+  %arrayidx4 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
+  %tmp2 = load i32, i32* %arrayidx4, align 4
+  %add = add nsw i32 %tmp2, %tmp1
+  store i32 %add, i32* %arrayidx4, 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