[polly] r309582 - [Simplify] Remove all kinds of redundant scalar writes.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 31 10:04:55 PDT 2017


Author: meinersbur
Date: Mon Jul 31 10:04:55 2017
New Revision: 309582

URL: http://llvm.org/viewvc/llvm-project?rev=309582&view=rev
Log:
[Simplify] Remove all kinds of redundant scalar writes.

In addition to array and PHI writes, also allow scalar value writes.
The only kind of write not allowed are writes by functions
(including memcpy/memmove/memset).

Added:
    polly/trunk/test/Simplify/redundant_scalarwrite.ll
    polly/trunk/test/Simplify/redundant_scalarwrite___%for---%return.jscop
    polly/trunk/test/Simplify/redundant_scalarwrite___%for---%return.jscop.transformed
Modified:
    polly/trunk/lib/Transform/Simplify.cpp
    polly/trunk/test/Simplify/gemm.ll

Modified: polly/trunk/lib/Transform/Simplify.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Transform/Simplify.cpp?rev=309582&r1=309581&r2=309582&view=diff
==============================================================================
--- polly/trunk/lib/Transform/Simplify.cpp (original)
+++ polly/trunk/lib/Transform/Simplify.cpp Mon Jul 31 10:04:55 2017
@@ -424,7 +424,8 @@ private:
           continue;
         if (!WA->isLatestArrayKind())
           continue;
-        if (!isa<StoreInst>(WA->getAccessInstruction()) && !WA->isPHIKind())
+        if (!isa<StoreInst>(WA->getAccessInstruction()) &&
+            !WA->isOriginalScalarKind())
           continue;
 
         llvm::Value *ReadingValue = WA->tryGetValueStored();

Modified: polly/trunk/test/Simplify/gemm.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Simplify/gemm.ll?rev=309582&r1=309581&r2=309582&view=diff
==============================================================================
--- polly/trunk/test/Simplify/gemm.ll (original)
+++ polly/trunk/test/Simplify/gemm.ll Mon Jul 31 10:04:55 2017
@@ -24,13 +24,7 @@
 ; CHECK-NEXT:             ReadAccess :=	[Reduction Type: NONE] [Scalar: 1]
 ; CHECK-NEXT:                 { Stmt_bb13[i0, i1, i2] -> MemRef_tmp_0[] };
 ; CHECK-NEXT:            new: { Stmt_bb13[i0, i1, i2] -> MemRef_C[i0, i1] };
-; CHECK-NEXT:     Stmt_bb11
-; CHECK-NEXT:             ReadAccess :=	[Reduction Type: NONE] [Scalar: 1]
-; CHECK-NEXT:                 { Stmt_bb11[i0, i1] -> MemRef_tmp_0_lcssa__phi[] };
-; CHECK-NEXT:            new: { Stmt_bb11[i0, i1] -> MemRef_C[i0, i1] };
-; CHECK-NEXT:             MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 1]
-; CHECK-NEXT:                 { Stmt_bb11[i0, i1] -> MemRef_tmp_0_lcssa[] };
-; CHECK-NEXT:            new: { Stmt_bb11[i0, i1] -> MemRef_C[i0, i1] };
+; CHECK-NEXT: }
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-pc-linux-gnu"

Added: polly/trunk/test/Simplify/redundant_scalarwrite.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Simplify/redundant_scalarwrite.ll?rev=309582&view=auto
==============================================================================
--- polly/trunk/test/Simplify/redundant_scalarwrite.ll (added)
+++ polly/trunk/test/Simplify/redundant_scalarwrite.ll Mon Jul 31 10:04:55 2017
@@ -0,0 +1,49 @@
+; RUN: opt %loadPolly -polly-import-jscop -polly-import-jscop-postfix=transformed -polly-simplify -analyze < %s | FileCheck %s -match-full-lines
+;
+; Remove redundant scalar stores.
+;
+; for (int j = 0; j < n; j += 1) {
+; bodyA:
+;   double val = A[0];
+;
+; bodyB:
+;   A[0] = val;
+; }
+;
+define void @redundant_scalarwrite(i32 %n, double* noalias nonnull %A) {
+entry:
+  br label %for
+
+for:
+  %j = phi i32 [0, %entry], [%j.inc, %inc]
+  %j.cmp = icmp slt i32 %j, %n
+  br i1 %j.cmp, label %bodyA, label %exit
+
+
+    bodyA:
+      %val = load double, double* %A
+      br label %bodyB
+
+    bodyB:
+      store double %val, double* %A
+      br label %inc
+
+
+inc:
+  %j.inc = add nuw nsw i32 %j, 1
+  br label %for
+
+exit:
+  br label %return
+
+return:
+  ret void
+}
+
+
+; CHECK: Statistics {
+; CHECK:     Redundant writes removed: 2
+; CHECK: }
+
+; CHECK:      After accesses {
+; CHECK-NEXT: }

Added: polly/trunk/test/Simplify/redundant_scalarwrite___%for---%return.jscop
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Simplify/redundant_scalarwrite___%25for---%25return.jscop?rev=309582&view=auto
==============================================================================
--- polly/trunk/test/Simplify/redundant_scalarwrite___%for---%return.jscop (added)
+++ polly/trunk/test/Simplify/redundant_scalarwrite___%for---%return.jscop Mon Jul 31 10:04:55 2017
@@ -0,0 +1,43 @@
+{
+   "arrays" : [
+      {
+         "name" : "MemRef_A",
+         "sizes" : [ "*" ],
+         "type" : "double"
+      }
+   ],
+   "context" : "[n] -> {  : -2147483648 <= n <= 2147483647 }",
+   "name" : "%for---%return",
+   "statements" : [
+      {
+         "accesses" : [
+            {
+               "kind" : "read",
+               "relation" : "[n] -> { Stmt_bodyA[i0] -> MemRef_A[0] }"
+            },
+            {
+               "kind" : "write",
+               "relation" : "[n] -> { Stmt_bodyA[i0] -> MemRef_val[] }"
+            }
+         ],
+         "domain" : "[n] -> { Stmt_bodyA[i0] : 0 <= i0 < n }",
+         "name" : "Stmt_bodyA",
+         "schedule" : "[n] -> { Stmt_bodyA[i0] -> [i0, 0] }"
+      },
+      {
+         "accesses" : [
+            {
+               "kind" : "write",
+               "relation" : "[n] -> { Stmt_bodyB[i0] -> MemRef_A[0] }"
+            },
+            {
+               "kind" : "read",
+               "relation" : "[n] -> { Stmt_bodyB[i0] -> MemRef_val[] }"
+            }
+         ],
+         "domain" : "[n] -> { Stmt_bodyB[i0] : 0 <= i0 < n }",
+         "name" : "Stmt_bodyB",
+         "schedule" : "[n] -> { Stmt_bodyB[i0] -> [i0, 1] }"
+      }
+   ]
+}

Added: polly/trunk/test/Simplify/redundant_scalarwrite___%for---%return.jscop.transformed
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Simplify/redundant_scalarwrite___%25for---%25return.jscop.transformed?rev=309582&view=auto
==============================================================================
--- polly/trunk/test/Simplify/redundant_scalarwrite___%for---%return.jscop.transformed (added)
+++ polly/trunk/test/Simplify/redundant_scalarwrite___%for---%return.jscop.transformed Mon Jul 31 10:04:55 2017
@@ -0,0 +1,43 @@
+{
+   "arrays" : [
+      {
+         "name" : "MemRef_A",
+         "sizes" : [ "*" ],
+         "type" : "double"
+      }
+   ],
+   "context" : "[n] -> {  : -2147483648 <= n <= 2147483647 }",
+   "name" : "%for---%return",
+   "statements" : [
+      {
+         "accesses" : [
+            {
+               "kind" : "read",
+               "relation" : "[n] -> { Stmt_bodyA[i0] -> MemRef_A[0] }"
+            },
+            {
+               "kind" : "write",
+               "relation" : "[n] -> { Stmt_bodyA[i0] -> MemRef_A[0] }"
+            }
+         ],
+         "domain" : "[n] -> { Stmt_bodyA[i0] : 0 <= i0 < n }",
+         "name" : "Stmt_bodyA",
+         "schedule" : "[n] -> { Stmt_bodyA[i0] -> [i0, 0] }"
+      },
+      {
+         "accesses" : [
+            {
+               "kind" : "write",
+               "relation" : "[n] -> { Stmt_bodyB[i0] -> MemRef_A[0] }"
+            },
+            {
+               "kind" : "read",
+               "relation" : "[n] -> { Stmt_bodyB[i0] -> MemRef_A[0] }"
+            }
+         ],
+         "domain" : "[n] -> { Stmt_bodyB[i0] : 0 <= i0 < n }",
+         "name" : "Stmt_bodyB",
+         "schedule" : "[n] -> { Stmt_bodyB[i0] -> [i0, 1] }"
+      }
+   ]
+}




More information about the llvm-commits mailing list