Skip to content

Commit c8a0e27

Browse files
committed
[Polly][OpTree] Fix mid-processing change of access kind.
Operand tree forwarding can cause the change of an access kind; in particular change from a scalar kind to an array kind if the scalar dependency is not necessary. Such an access cannot and doesn't need to be forwarded anymore. Fixes llvm.org/PR48034
1 parent c1cf51e commit c8a0e27

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

polly/lib/Transform/ForwardOpTree.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -979,17 +979,14 @@ class ForwardOpTreeImpl : ZoneAlgorithm {
979979

980980
// Because we are modifying the MemoryAccess list, collect them first to
981981
// avoid iterator invalidation.
982-
SmallVector<MemoryAccess *, 16> Accs;
983-
for (MemoryAccess *RA : Stmt) {
982+
SmallVector<MemoryAccess *, 16> Accs(Stmt.begin(), Stmt.end());
983+
984+
for (MemoryAccess *RA : Accs) {
984985
if (!RA->isRead())
985986
continue;
986987
if (!RA->isLatestScalarKind())
987988
continue;
988989

989-
Accs.push_back(RA);
990-
}
991-
992-
for (MemoryAccess *RA : Accs) {
993990
if (tryForwardTree(RA)) {
994991
Modified = true;
995992
StmtModified = true;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
; RUN: opt %loadPolly -polly-optree -analyze < %s | FileCheck %s -match-full-lines
2+
3+
; In the code below, %0 is known to be equal to the content of @c (constant 0).
4+
; Thus, in order to save a scalar dependency, forward-optree replaces
5+
; the use of %0 in Stmt_lor_end93 by a load from @c by changing the
6+
; access find from a scalar access to a array accesses.
7+
; llvm.org/PR48034 decribes a crash caused by the mid-processing change.
8+
9+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
10+
target triple = "x86_64-unknown-linux-gnu"
11+
12+
@c = external dso_local global i64, align 8
13+
14+
define void @func() {
15+
entry:
16+
br label %lor.end
17+
18+
while.cond.loopexit:
19+
%conv102.le = trunc i64 %xor101 to i8
20+
ret void
21+
22+
lor.end:
23+
%tobool72.not = icmp eq i64 0, 0
24+
br i1 %tobool72.not, label %lor.rhs87, label %lor.end.thread
25+
26+
lor.end.thread:
27+
br label %lor.rhs87
28+
29+
lor.rhs87:
30+
%0 = phi i64 [ 0, %lor.end.thread ], [ 0, %lor.end ]
31+
store i64 %0, i64* @c, align 8
32+
%neg79 = xor i64 %0, -1
33+
br label %lor.end93
34+
35+
lor.end93:
36+
%tobool93 = icmp ne i64 undef, 0
37+
%conv95 = zext i1 %tobool93 to i64
38+
%and100 = and i64 %conv95, undef
39+
%xor101 = xor i64 %and100, %neg79
40+
%xor103 = xor i64 %0, %conv95
41+
br label %while.cond.loopexit
42+
}
43+
44+
45+
; CHECK: Statistics {
46+
; CHECK: Reloads: 1
47+
; CHECK: }
48+
49+
; CHECK: After statements {
50+
; CHECK: Stmt_lor_end93
51+
; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1]
52+
; CHECK-NEXT: { Stmt_lor_end93[] -> MemRef3[] };
53+
; CHECK-NEXT: new: { Stmt_lor_end93[] -> MemRef_c[0] };
54+
; CHECK: }

0 commit comments

Comments
 (0)