[polly] r312456 - [ForwardOp] Remove read accesses for all instructions that have been moved

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 3 12:52:15 PDT 2017


Author: grosser
Date: Sun Sep  3 12:52:15 2017
New Revision: 312456

URL: http://llvm.org/viewvc/llvm-project?rev=312456&view=rev
Log:
[ForwardOp] Remove read accesses for all instructions that have been moved

Before this patch, OpTree did not consider forwarding an operand tree consisting
of only single LoadInst as useful. The motivation was that, like an access to a
read-only variable, it would just replace one MemoryAccess by another. However,
in contrast to read-only accesses, this would replace a scalar access by an
array access, which is something worth doing.

In addition, leaving scalar MemoryAccess is problematic in that VirtualUse
prioritizes inter-Stmt use over intra-Stmt. It was possible that the same LLVM
value has a MemoryAccess for accessing the remote Stmt's LoadInst as well as
having the same LoadInst in its own instruction list (due to being forwarded
from another operand tree).

With this patch we ensure that if a LoadInst is forwarded is any operand tree,
also the operand tree containing just the LoadInst is forwarded as well, which
effectively removes the scalar MemoryAccess such that only the array access
remains, not both.

Thanks Michael for the detailed explanation.

Reviewers: Meinersbur, bellu, singam-sanjay, gareevroman

Subscribers: hfinkel, pollydev, llvm-commits

Tags: #polly

Differential Revision: https://reviews.llvm.org/D37424

Added:
    polly/trunk/test/ForwardOpTree/forward_into_region_redundant_use.ll
Modified:
    polly/trunk/lib/Transform/ForwardOpTree.cpp
    polly/trunk/test/ForwardOpTree/forward_load_tripleuse.ll

Modified: polly/trunk/lib/Transform/ForwardOpTree.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Transform/ForwardOpTree.cpp?rev=312456&r1=312455&r2=312456&view=diff
==============================================================================
--- polly/trunk/lib/Transform/ForwardOpTree.cpp (original)
+++ polly/trunk/lib/Transform/ForwardOpTree.cpp Sun Sep  3 12:52:15 2017
@@ -420,7 +420,7 @@ public:
     //   do not add another MemoryAccess.
     MemoryAccess *Access = TargetStmt->getArrayAccessOrNULLFor(LI);
     if (Access && !DoIt)
-      return FD_CanForwardLeaf;
+      return FD_CanForwardTree;
 
     if (DoIt)
       TargetStmt->prependInstruction(LI);

Added: polly/trunk/test/ForwardOpTree/forward_into_region_redundant_use.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ForwardOpTree/forward_into_region_redundant_use.ll?rev=312456&view=auto
==============================================================================
--- polly/trunk/test/ForwardOpTree/forward_into_region_redundant_use.ll (added)
+++ polly/trunk/test/ForwardOpTree/forward_into_region_redundant_use.ll Sun Sep  3 12:52:15 2017
@@ -0,0 +1,57 @@
+; RUN: opt %loadPolly -polly-invariant-load-hoisting=true -polly-optree -analyze < %s | FileCheck %s -match-full-lines
+;
+
+define void @foo(float* %A, i32 %p, float* %B) {
+start:
+  br label %branch
+
+branch:
+  %cmp = icmp eq i32 %p, 1024
+  br i1 %cmp, label %next, label %end
+
+next:
+  %val = load float, float* %A
+  %fcmp = fcmp oeq float %val, 41.0
+  br label %nonaffine
+
+nonaffine:
+  br i1 %fcmp, label %a, label %b
+
+a:
+  store float %val, float* %A
+  br label %end
+
+b:
+  store float 1.0, float* %A
+  br label %end
+
+end:
+  ret void
+}
+
+; CHECK:      After statements {
+; CHECK-NEXT:     Stmt_next
+; CHECK-NEXT:             ReadAccess :=	[Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT:                 [p] -> { Stmt_next[] -> MemRef_A[0] };
+; CHECK-NEXT:             MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 1]
+; CHECK-NEXT:                 [p] -> { Stmt_next[] -> MemRef_fcmp[] };
+; CHECK-NEXT:             MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 1]
+; CHECK-NEXT:                 [p] -> { Stmt_next[] -> MemRef_val[] };
+; CHECK-NEXT:             Instructions {
+; CHECK-NEXT:                   %val = load float, float* %A
+; CHECK-NEXT:                   %fcmp = fcmp oeq float %val, 4.100000e+01
+; CHECK-NEXT:             }
+; CHECK-NEXT:     Stmt_nonaffine__TO__end
+; CHECK-NEXT:             ReadAccess :=	[Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT:                 null;
+; CHECK-NEXT:            new: [p] -> { Stmt_nonaffine__TO__end[] -> MemRef_A[0] };
+; CHECK-NEXT:             MayWriteAccess :=	[Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT:                 [p] -> { Stmt_nonaffine__TO__end[] -> MemRef_A[0] };
+; CHECK-NEXT:             MayWriteAccess :=	[Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT:                 [p] -> { Stmt_nonaffine__TO__end[] -> MemRef_A[0] };
+; CHECK-NEXT:             Instructions {
+; CHECK-NEXT:                   %val = load float, float* %A
+; CHECK-NEXT:                   %val = load float, float* %A
+; CHECK-NEXT:                   %fcmp = fcmp oeq float %val, 4.100000e+01
+; CHECK-NEXT:             }
+; CHECK-NEXT: }

Modified: polly/trunk/test/ForwardOpTree/forward_load_tripleuse.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ForwardOpTree/forward_load_tripleuse.ll?rev=312456&r1=312455&r2=312456&view=diff
==============================================================================
--- polly/trunk/test/ForwardOpTree/forward_load_tripleuse.ll (original)
+++ polly/trunk/test/ForwardOpTree/forward_load_tripleuse.ll Sun Sep  3 12:52:15 2017
@@ -125,8 +125,8 @@ return:
 
 ; CHECK: Statistics {
 ; CHECK:     Instructions copied: 1
-; CHECK:     Known loads forwarded: 2
-; CHECK:     Operand trees forwarded: 1
+; CHECK:     Known loads forwarded: 3
+; CHECK:     Operand trees forwarded: 2
 ; CHECK:     Statements with forwarded operand trees: 1
 ; CHECK: }
 
@@ -150,11 +150,10 @@ return:
 ; CHECK-NEXT:                 [n] -> { Stmt_bodyB[i0] -> MemRef_B[i0] };
 ; CHECK-NEXT:             MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 0]
 ; CHECK-NEXT:                 [n] -> { Stmt_bodyB[i0] -> MemRef_C[i0] };
-; CHECK-NEXT:             ReadAccess :=       [Reduction Type: NONE] [Scalar: 1]
-; CHECK-NEXT:                 [n] -> { Stmt_bodyB[i0] -> MemRef_val1[] };
 ; CHECK-NEXT:             Instructions {
 ; CHECK-NEXT:                   %val1 = load double, double* %A_idx
 ; CHECK-NEXT:                   %val1 = load double, double* %A_idx
+; CHECK-NEXT:                   %val1 = load double, double* %A_idx
 ; CHECK-NEXT:                   %val2 = fadd double %val1, %val1
 ; CHECK-NEXT:                   store double %val2, double* %B_idx
 ; CHECK-NEXT:                   store double %val1, double* %C_idx




More information about the llvm-commits mailing list