Skip to content

Commit 1c4b5a8

Browse files
committed
Merging r372188:
------------------------------------------------------------------------ r372188 | meinersbur | 2019-09-17 15:59:43 -0700 (Tue, 17 Sep 2019) | 13 lines [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 ------------------------------------------------------------------------ llvm-svn: 374861
1 parent 99e5b1a commit 1c4b5a8

File tree

2 files changed

+76
-3
lines changed

2 files changed

+76
-3
lines changed

polly/lib/CodeGen/IslNodeBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,12 @@ void addReferencesFromStmt(const ScopStmt *Stmt, void *UserPtr,
231231

232232
if (Stmt->isBlockStmt())
233233
findReferencesInBlock(References, Stmt, Stmt->getBasicBlock());
234-
else {
235-
assert(Stmt->isRegionStmt() &&
236-
"Stmt was neither block nor region statement");
234+
else if (Stmt->isRegionStmt()) {
237235
for (BasicBlock *BB : Stmt->getRegion()->blocks())
238236
findReferencesInBlock(References, Stmt, BB);
237+
} else {
238+
assert(Stmt->isCopyStmt());
239+
// Copy Stmts have no instructions that we need to consider.
239240
}
240241

241242
for (auto &Access : *Stmt) {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
; RUN: opt %loadPolly -polly-parallel -polly-opt-isl -polly-ast -disable-output -debug-only=polly-ast < %s 2>&1 | FileCheck --check-prefix=AST %s
2+
; RUN: opt %loadPolly -polly-parallel -polly-opt-isl -polly-codegen -S < %s | FileCheck --check-prefix=CODEGEN %s
3+
; REQUIRES: asserts
4+
5+
; Parellization of detected matrix-multiplication. The allocations
6+
; Packed_A and Packed_B must be passed to the outlined function.
7+
; llvm.org/PR43164
8+
;
9+
; #define N 1536
10+
; int foo(float A[N][N],float B[N][N],float C[N][N]) {
11+
; for (int i = 0; i < N; i++) {
12+
; for (int j = 0; j < N; j++) {
13+
; for (int k = 0; k < N; k++)
14+
; C[i][j] = C[i][j] + A[i][k] * B[k][j];
15+
; }
16+
; }
17+
; return 0;
18+
; }
19+
20+
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
21+
target triple = "x86_64-pc-windows-msvc19.16.27034"
22+
23+
define i32 @foo([1536 x float]* nocapture readonly %A, [1536 x float]* nocapture readonly %B, [1536 x float]* nocapture %C) {
24+
entry:
25+
br label %entry.split
26+
27+
entry.split:
28+
br label %for.cond1.preheader
29+
30+
for.cond1.preheader:
31+
%indvars.iv50 = phi i64 [ 0, %entry.split ], [ %indvars.iv.next51, %for.cond.cleanup3 ]
32+
br label %for.cond5.preheader
33+
34+
for.cond.cleanup:
35+
ret i32 0
36+
37+
for.cond5.preheader:
38+
%indvars.iv47 = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next48, %for.cond.cleanup7 ]
39+
%arrayidx10 = getelementptr inbounds [1536 x float], [1536 x float]* %C, i64 %indvars.iv50, i64 %indvars.iv47
40+
br label %for.body8
41+
42+
for.cond.cleanup3:
43+
%indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
44+
%exitcond52 = icmp eq i64 %indvars.iv.next51, 1536
45+
br i1 %exitcond52, label %for.cond.cleanup, label %for.cond1.preheader
46+
47+
for.cond.cleanup7:
48+
%indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
49+
%exitcond49 = icmp eq i64 %indvars.iv.next48, 1536
50+
br i1 %exitcond49, label %for.cond.cleanup3, label %for.cond5.preheader
51+
52+
for.body8:
53+
%indvars.iv = phi i64 [ 0, %for.cond5.preheader ], [ %indvars.iv.next, %for.body8 ]
54+
%0 = load float, float* %arrayidx10, align 4
55+
%arrayidx14 = getelementptr inbounds [1536 x float], [1536 x float]* %A, i64 %indvars.iv50, i64 %indvars.iv
56+
%1 = load float, float* %arrayidx14, align 4
57+
%arrayidx18 = getelementptr inbounds [1536 x float], [1536 x float]* %B, i64 %indvars.iv, i64 %indvars.iv47
58+
%2 = load float, float* %arrayidx18, align 4
59+
%mul = fmul float %1, %2
60+
%add = fadd float %0, %mul
61+
store float %add, float* %arrayidx10, align 4
62+
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
63+
%exitcond = icmp eq i64 %indvars.iv.next, 1536
64+
br i1 %exitcond, label %for.cond.cleanup7, label %for.body8
65+
}
66+
67+
68+
; AST: #pragma omp parallel for
69+
70+
; CODGEN-LABEL: define internal void @init_array_polly_subfn(i8* %polly.par.userContext)
71+
; CODEGEN: %polly.subfunc.arg.Packed_A = load
72+
; CODEGEN: %polly.subfunc.arg.Packed_B = load

0 commit comments

Comments
 (0)