[polly] r372188 - [CodeGen] Handle outlining of CopyStmts.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 17 15:59:43 PDT 2019


Author: meinersbur
Date: Tue Sep 17 15:59:43 2019
New Revision: 372188

URL: http://llvm.org/viewvc/llvm-project?rev=372188&view=rev
Log:
[CodeGen] Handle outlining of CopyStmts.

Since the removal of extensions nodes from schedule trees in r362257 it
is possible to emit parallel code for SCoPs containing
matrix-multiplications. However, the code looking for references used in
outlined statement was not prepared to handle CopyStmts introduced by
the matrix-matrix multiplication detection.

In this case, CopyStmts do not introduce references in addition to the
ones captured by MemoryAccesses, i.e. we change the assertion to accept
CopyStmts and add a regression test for this case.

This fixes llvm.org/PR43164

Added:
    polly/trunk/test/Isl/CodeGen/OpenMP/matmul-parallel.ll
Modified:
    polly/trunk/lib/CodeGen/IslNodeBuilder.cpp

Modified: polly/trunk/lib/CodeGen/IslNodeBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslNodeBuilder.cpp?rev=372188&r1=372187&r2=372188&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslNodeBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslNodeBuilder.cpp Tue Sep 17 15:59:43 2019
@@ -231,11 +231,12 @@ void addReferencesFromStmt(const ScopStm
 
   if (Stmt->isBlockStmt())
     findReferencesInBlock(References, Stmt, Stmt->getBasicBlock());
-  else {
-    assert(Stmt->isRegionStmt() &&
-           "Stmt was neither block nor region statement");
+  else if (Stmt->isRegionStmt()) {
     for (BasicBlock *BB : Stmt->getRegion()->blocks())
       findReferencesInBlock(References, Stmt, BB);
+  } else {
+    assert(Stmt->isCopyStmt());
+    // Copy Stmts have no instructions that we need to consider.
   }
 
   for (auto &Access : *Stmt) {

Added: polly/trunk/test/Isl/CodeGen/OpenMP/matmul-parallel.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/OpenMP/matmul-parallel.ll?rev=372188&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/OpenMP/matmul-parallel.ll (added)
+++ polly/trunk/test/Isl/CodeGen/OpenMP/matmul-parallel.ll Tue Sep 17 15:59:43 2019
@@ -0,0 +1,72 @@
+; RUN: opt %loadPolly -polly-parallel -polly-opt-isl -polly-ast -disable-output -debug-only=polly-ast < %s 2>&1 | FileCheck --check-prefix=AST %s
+; RUN: opt %loadPolly -polly-parallel -polly-opt-isl -polly-codegen -S < %s | FileCheck --check-prefix=CODEGEN %s
+; REQUIRES: asserts
+
+; Parellization of detected matrix-multiplication. The allocations
+; Packed_A and Packed_B must be passed to the outlined function.
+; llvm.org/PR43164
+;
+; #define N 1536
+; int foo(float A[N][N],float B[N][N],float C[N][N]) {
+;     for (int i = 0; i < N; i++) {
+;         for (int j = 0; j < N; j++) {
+;             for (int k = 0; k < N; k++)
+;                 C[i][j] = C[i][j] + A[i][k] * B[k][j];
+;         }
+;     }
+;     return 0;
+; }
+
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.16.27034"
+
+define i32 @foo([1536 x float]* nocapture readonly %A, [1536 x float]* nocapture readonly %B, [1536 x float]* nocapture %C) {
+entry:
+  br label %entry.split
+
+entry.split:
+  br label %for.cond1.preheader
+
+for.cond1.preheader:
+  %indvars.iv50 = phi i64 [ 0, %entry.split ], [ %indvars.iv.next51, %for.cond.cleanup3 ]
+  br label %for.cond5.preheader
+
+for.cond.cleanup:
+  ret i32 0
+
+for.cond5.preheader:
+  %indvars.iv47 = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next48, %for.cond.cleanup7 ]
+  %arrayidx10 = getelementptr inbounds [1536 x float], [1536 x float]* %C, i64 %indvars.iv50, i64 %indvars.iv47
+  br label %for.body8
+
+for.cond.cleanup3:
+  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
+  %exitcond52 = icmp eq i64 %indvars.iv.next51, 1536
+  br i1 %exitcond52, label %for.cond.cleanup, label %for.cond1.preheader
+
+for.cond.cleanup7:
+  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
+  %exitcond49 = icmp eq i64 %indvars.iv.next48, 1536
+  br i1 %exitcond49, label %for.cond.cleanup3, label %for.cond5.preheader
+
+for.body8:
+  %indvars.iv = phi i64 [ 0, %for.cond5.preheader ], [ %indvars.iv.next, %for.body8 ]
+  %0 = load float, float* %arrayidx10, align 4
+  %arrayidx14 = getelementptr inbounds [1536 x float], [1536 x float]* %A, i64 %indvars.iv50, i64 %indvars.iv
+  %1 = load float, float* %arrayidx14, align 4
+  %arrayidx18 = getelementptr inbounds [1536 x float], [1536 x float]* %B, i64 %indvars.iv, i64 %indvars.iv47
+  %2 = load float, float* %arrayidx18, align 4
+  %mul = fmul float %1, %2
+  %add = fadd float %0, %mul
+  store float %add, float* %arrayidx10, align 4
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond = icmp eq i64 %indvars.iv.next, 1536
+  br i1 %exitcond, label %for.cond.cleanup7, label %for.body8
+}
+
+
+; AST: #pragma omp parallel for
+
+; CODGEN-LABEL: define internal void @init_array_polly_subfn(i8* %polly.par.userContext)
+; CODEGEN: %polly.subfunc.arg.Packed_A = load
+; CODEGEN: %polly.subfunc.arg.Packed_B = load




More information about the llvm-commits mailing list