[polly] r316660 - [Simplify] Mark (and sweep) based on latest access relation.
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 26 05:34:36 PDT 2017
Author: meinersbur
Date: Thu Oct 26 05:34:36 2017
New Revision: 316660
URL: http://llvm.org/viewvc/llvm-project?rev=316660&view=rev
Log:
[Simplify] Mark (and sweep) based on latest access relation.
Previously we marked scalars based on the original access function. However,
when a scalar read access is redirected, the original definition
(or incoming values of a PHI) is not used anymore, and can be deleted
(unless referenced by use that has not been redirected).
Added:
polly/trunk/test/Simplify/sweep_mapped_phi.ll
polly/trunk/test/Simplify/sweep_mapped_phi___%for---%return.jscop
polly/trunk/test/Simplify/sweep_mapped_phi___%for---%return.jscop.transformed
polly/trunk/test/Simplify/sweep_mapped_value.ll
polly/trunk/test/Simplify/sweep_mapped_value___%for---%return.jscop
polly/trunk/test/Simplify/sweep_mapped_value___%for---%return.jscop.transformed
Modified:
polly/trunk/lib/Support/VirtualInstruction.cpp
Modified: polly/trunk/lib/Support/VirtualInstruction.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/VirtualInstruction.cpp?rev=316660&r1=316659&r2=316660&view=diff
==============================================================================
--- polly/trunk/lib/Support/VirtualInstruction.cpp (original)
+++ polly/trunk/lib/Support/VirtualInstruction.cpp Thu Oct 26 05:34:36 2017
@@ -311,7 +311,7 @@ static void walkReachable(Scop *S, LoopI
if (Acc->isRead()) {
const ScopArrayInfo *SAI = Acc->getScopArrayInfo();
- if (Acc->isOriginalValueKind()) {
+ if (Acc->isLatestValueKind()) {
MemoryAccess *DefAcc = S->getValueDef(SAI);
// Accesses to read-only values do not have a definition.
@@ -319,7 +319,7 @@ static void walkReachable(Scop *S, LoopI
WorklistAccs.push_back(S->getValueDef(SAI));
}
- if (Acc->isOriginalAnyPHIKind()) {
+ if (Acc->isLatestAnyPHIKind()) {
auto IncomingMAs = S->getPHIIncomings(SAI);
WorklistAccs.append(IncomingMAs.begin(), IncomingMAs.end());
}
Added: polly/trunk/test/Simplify/sweep_mapped_phi.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Simplify/sweep_mapped_phi.ll?rev=316660&view=auto
==============================================================================
--- polly/trunk/test/Simplify/sweep_mapped_phi.ll (added)
+++ polly/trunk/test/Simplify/sweep_mapped_phi.ll Thu Oct 26 05:34:36 2017
@@ -0,0 +1,62 @@
+; RUN: opt %loadPolly -polly-import-jscop -polly-import-jscop-postfix=transformed -polly-simplify -analyze < %s | FileCheck %s -match-full-lines
+;
+; Map %phi to A[j], so the scalar write in Stmt_for_bodyA can be removed.
+;
+; for (int j = 0; j < n; j += 1) {
+; bodyA:
+; val = 21.0 + 21.0;
+; A[j] = val;
+;
+; bodyB:
+; B[j] = val;
+; }
+;
+
+define void @sweep_mapped_phi(i32 %n, double* noalias nonnull %A, double* noalias nonnull %B) {
+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 = fadd double 21.0, 21.0
+ %A_idx = getelementptr inbounds double, double* %A, i32 %j
+ store double %val, double* %A_idx
+ br label %bodyB
+
+ bodyB:
+ %phi = phi double [%val, %bodyA]
+ %B_idx = getelementptr inbounds double, double* %B, i32 %j
+ store double %phi, double* %B_idx
+ 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: Dead accesses removed: 1
+; CHECK: }
+
+; CHECK: After accesses {
+; CHECK-NEXT: Stmt_bodyA
+; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT: [n] -> { Stmt_bodyA[i0] -> MemRef_A[i0] };
+; CHECK-NEXT: Stmt_bodyB
+; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1]
+; CHECK-NEXT: [n] -> { Stmt_bodyB[i0] -> MemRef_phi__phi[] };
+; CHECK-NEXT: new: [n] -> { Stmt_bodyB[i0] -> MemRef_A[i0] };
+; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT: [n] -> { Stmt_bodyB[i0] -> MemRef_B[i0] };
+; CHECK-NEXT: }
Added: polly/trunk/test/Simplify/sweep_mapped_phi___%for---%return.jscop
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Simplify/sweep_mapped_phi___%25for---%25return.jscop?rev=316660&view=auto
==============================================================================
--- polly/trunk/test/Simplify/sweep_mapped_phi___%for---%return.jscop (added)
+++ polly/trunk/test/Simplify/sweep_mapped_phi___%for---%return.jscop Thu Oct 26 05:34:36 2017
@@ -0,0 +1,48 @@
+{
+ "arrays" : [
+ {
+ "name" : "MemRef_A",
+ "sizes" : [ "*" ],
+ "type" : "double"
+ },
+ {
+ "name" : "MemRef_B",
+ "sizes" : [ "*" ],
+ "type" : "double"
+ }
+ ],
+ "context" : "[n] -> { : -2147483648 <= n <= 2147483647 }",
+ "name" : "%for---%return",
+ "statements" : [
+ {
+ "accesses" : [
+ {
+ "kind" : "write",
+ "relation" : "[n] -> { Stmt_bodyA[i0] -> MemRef_A[i0] }"
+ },
+ {
+ "kind" : "write",
+ "relation" : "[n] -> { Stmt_bodyA[i0] -> MemRef_phi__phi[] }"
+ }
+ ],
+ "domain" : "[n] -> { Stmt_bodyA[i0] : 0 <= i0 < n }",
+ "name" : "Stmt_bodyA",
+ "schedule" : "[n] -> { Stmt_bodyA[i0] -> [i0, 0] }"
+ },
+ {
+ "accesses" : [
+ {
+ "kind" : "read",
+ "relation" : "[n] -> { Stmt_bodyB[i0] -> MemRef_phi__phi[] }"
+ },
+ {
+ "kind" : "write",
+ "relation" : "[n] -> { Stmt_bodyB[i0] -> MemRef_B[i0] }"
+ }
+ ],
+ "domain" : "[n] -> { Stmt_bodyB[i0] : 0 <= i0 < n }",
+ "name" : "Stmt_bodyB",
+ "schedule" : "[n] -> { Stmt_bodyB[i0] -> [i0, 1] }"
+ }
+ ]
+}
Added: polly/trunk/test/Simplify/sweep_mapped_phi___%for---%return.jscop.transformed
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Simplify/sweep_mapped_phi___%25for---%25return.jscop.transformed?rev=316660&view=auto
==============================================================================
--- polly/trunk/test/Simplify/sweep_mapped_phi___%for---%return.jscop.transformed (added)
+++ polly/trunk/test/Simplify/sweep_mapped_phi___%for---%return.jscop.transformed Thu Oct 26 05:34:36 2017
@@ -0,0 +1,65 @@
+{
+ "arrays" : [
+ {
+ "name" : "MemRef_A",
+ "sizes" : [ "*" ],
+ "type" : "double"
+ },
+ {
+ "name" : "MemRef_B",
+ "sizes" : [ "*" ],
+ "type" : "double"
+ }
+ ],
+ "context" : "[n] -> { : -2147483648 <= n <= 2147483647 }",
+ "name" : "%for---%return",
+ "statements" : [
+ {
+ "accesses" : [
+ {
+ "kind" : "write",
+ "relation" : "[n] -> { Stmt_bodyA[i0] -> MemRef_A[i0] }"
+ },
+ {
+ "kind" : "write",
+ "relation" : "[n] -> { Stmt_bodyA[i0] -> MemRef_phi__phi[] }"
+ }
+ ],
+ "domain" : "[n] -> { Stmt_bodyA[i0] : 0 <= i0 < n }",
+ "name" : "Stmt_bodyA",
+ "schedule" : "[n] -> { Stmt_bodyA[i0] -> [i0, 0] }"
+ },
+ {
+ "accesses" : [
+ {
+ "kind" : "read",
+ "relation" : "[n] -> { Stmt_bodyB[i0] -> MemRef_A[i0] }"
+ },
+ {
+ "kind" : "write",
+ "relation" : "[n] -> { Stmt_bodyB[i0] -> MemRef_B[i0] }"
+ }
+ ],
+ "domain" : "[n] -> { Stmt_bodyB[i0] : 0 <= i0 < n }",
+ "name" : "Stmt_bodyB",
+ "schedule" : "[n] -> { Stmt_bodyB[i0] -> [i0, 1] }"
+ }
+ ]
+}
+
+
+; CHECK: Statistics {
+; CHECK: Dead accesses removed: 1
+; CHECK: }
+
+; CHECK: After accesses {
+; CHECK-NEXT: Stmt_bodyA
+; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT: [n] -> { Stmt_bodyA[i0] -> MemRef_A[i0] };
+; CHECK-NEXT: Stmt_bodyB
+; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1]
+; CHECK-NEXT: [n] -> { Stmt_bodyB[i0] -> MemRef_phi__phi[] };
+; CHECK-NEXT: new: [n] -> { Stmt_bodyB[i0] -> MemRef_A[i0] };
+; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT: [n] -> { Stmt_bodyB[i0] -> MemRef_B[i0] };
+; CHECK-NEXT: }
Added: polly/trunk/test/Simplify/sweep_mapped_value.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Simplify/sweep_mapped_value.ll?rev=316660&view=auto
==============================================================================
--- polly/trunk/test/Simplify/sweep_mapped_value.ll (added)
+++ polly/trunk/test/Simplify/sweep_mapped_value.ll Thu Oct 26 05:34:36 2017
@@ -0,0 +1,61 @@
+; RUN: opt %loadPolly -polly-import-jscop -polly-import-jscop-postfix=transformed -polly-simplify -analyze < %s | FileCheck %s -match-full-lines
+;
+; Map %val to A[j], so the scalar write on Stmt_for_bodyB can be removed.
+;
+; for (int j = 0; j < n; j += 1) {
+; bodyA:
+; double val = 21.0 + 21.0;
+; A[j] = val;
+;
+; bodyB:
+; B[j] = val;
+; }
+;
+
+define void @sweep_mapped_value(i32 %n, double* noalias nonnull %A, double* noalias nonnull %B) {
+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 = fadd double 21.0, 21.0
+ %A_idx = getelementptr inbounds double, double* %A, i32 %j
+ store double %val, double* %A_idx
+ br label %bodyB
+
+ bodyB:
+ %B_idx = getelementptr inbounds double, double* %B, i32 %j
+ store double %val, double* %B_idx
+ 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: Dead accesses removed: 1
+; CHECK: }
+
+; CHECK: After accesses {
+; CHECK-NEXT: Stmt_bodyA
+; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT: [n] -> { Stmt_bodyA[i0] -> MemRef_A[i0] };
+; CHECK-NEXT: Stmt_bodyB
+; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT: [n] -> { Stmt_bodyB[i0] -> MemRef_B[i0] };
+; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1]
+; CHECK-NEXT: [n] -> { Stmt_bodyB[i0] -> MemRef_val[] };
+; CHECK-NEXT: new: [n] -> { Stmt_bodyB[i0] -> MemRef_A[i0] };
+; CHECK-NEXT: }
Added: polly/trunk/test/Simplify/sweep_mapped_value___%for---%return.jscop
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Simplify/sweep_mapped_value___%25for---%25return.jscop?rev=316660&view=auto
==============================================================================
--- polly/trunk/test/Simplify/sweep_mapped_value___%for---%return.jscop (added)
+++ polly/trunk/test/Simplify/sweep_mapped_value___%for---%return.jscop Thu Oct 26 05:34:36 2017
@@ -0,0 +1,48 @@
+{
+ "arrays" : [
+ {
+ "name" : "MemRef_A",
+ "sizes" : [ "*" ],
+ "type" : "double"
+ },
+ {
+ "name" : "MemRef_B",
+ "sizes" : [ "*" ],
+ "type" : "double"
+ }
+ ],
+ "context" : "[n] -> { : -2147483648 <= n <= 2147483647 }",
+ "name" : "%for---%return",
+ "statements" : [
+ {
+ "accesses" : [
+ {
+ "kind" : "write",
+ "relation" : "[n] -> { Stmt_bodyA[i0] -> MemRef_A[i0] }"
+ },
+ {
+ "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_B[i0] }"
+ },
+ {
+ "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/sweep_mapped_value___%for---%return.jscop.transformed
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Simplify/sweep_mapped_value___%25for---%25return.jscop.transformed?rev=316660&view=auto
==============================================================================
--- polly/trunk/test/Simplify/sweep_mapped_value___%for---%return.jscop.transformed (added)
+++ polly/trunk/test/Simplify/sweep_mapped_value___%for---%return.jscop.transformed Thu Oct 26 05:34:36 2017
@@ -0,0 +1,48 @@
+{
+ "arrays" : [
+ {
+ "name" : "MemRef_A",
+ "sizes" : [ "*" ],
+ "type" : "double"
+ },
+ {
+ "name" : "MemRef_B",
+ "sizes" : [ "*" ],
+ "type" : "double"
+ }
+ ],
+ "context" : "[n] -> { : -2147483648 <= n <= 2147483647 }",
+ "name" : "%for---%return",
+ "statements" : [
+ {
+ "accesses" : [
+ {
+ "kind" : "write",
+ "relation" : "[n] -> { Stmt_bodyA[i0] -> MemRef_A[i0] }"
+ },
+ {
+ "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_B[i0] }"
+ },
+ {
+ "kind" : "read",
+ "relation" : "[n] -> { Stmt_bodyB[i0] -> MemRef_A[i0] }"
+ }
+ ],
+ "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