Skip to content

Commit f9f073a

Browse files
committed
[MemorySSA] Add previous def to cache when found, even if trivial.
Summary: When inserting a new Def, MemorySSA may be have non-minimal number of Phis. While inserting, the walk to find the previous definition may cleanup minimal Phis. When the last definition is trivial to obtain, we do not cache it. It is possible while getting the previous definition for a Def to get two different answers: - one that was straight-forward to find when walking the first path (a trivial phi in this case), and - another that follows a cleanup of the trivial phi, it determines it may need additional Phi nodes, it inserts them and returns a new phi in the same position as the former trivial one. While the Phis added for the second path are all redundant, they are not complete (the walk is only done upwards), and they are not properly cleaned up afterwards. A way to fix this problem is to cache the straight-forward answer we got on the first walk. The caching is only kept for the duration of a getPreviousDef call, and for Phis we use TrackingVH, so removing the trivial phi will lead to replacing it with the next dominating phi in the cache. Resolves PR40749. Reviewers: george.burgess.iv Subscribers: jlebar, Prazek, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60634 llvm-svn: 358313
1 parent 2806fd0 commit f9f073a

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

llvm/lib/Analysis/MemorySSAUpdater.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ MemoryAccess *MemorySSAUpdater::getPreviousDefFromEnd(
156156
DenseMap<BasicBlock *, TrackingVH<MemoryAccess>> &CachedPreviousDef) {
157157
auto *Defs = MSSA->getWritableBlockDefs(BB);
158158

159-
if (Defs)
159+
if (Defs) {
160+
CachedPreviousDef.insert({BB, &*Defs->rbegin()});
160161
return &*Defs->rbegin();
162+
}
161163

162164
return getPreviousDefRecursive(BB, CachedPreviousDef);
163165
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
; RUN: opt -S -licm -loop-unswitch -enable-mssa-loop-dependency -verify-memoryssa %s | FileCheck %s
2+
; REQUIRES: asserts
3+
target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"
4+
target triple = "s390x-ibm-linux"
5+
6+
@g_92 = external dso_local local_unnamed_addr global i16, align 2
7+
@g_993 = external dso_local local_unnamed_addr global i32, align 4
8+
9+
; CHECK-LABEL: @ff6
10+
define dso_local fastcc void @ff6(i16 %arg1) unnamed_addr #0 {
11+
bb:
12+
%tmp6.i = icmp sgt i16 %arg1, 0
13+
br label %bb10
14+
15+
bb10: ; preds = %bb81.loopexit, %bb
16+
%tmp17 = load i16, i16* @g_92, align 2
17+
%tmp18 = add i16 %tmp17, 1
18+
store i16 %tmp18, i16* @g_92, align 2
19+
br label %bb19
20+
21+
bb19: ; preds = %bb42, %bb10
22+
br label %bb24.preheader
23+
24+
bb24.preheader: ; preds = %bb75, %bb19
25+
store i32 0, i32* @g_993, align 4
26+
br i1 %tmp6.i, label %bb24.preheader.split.us, label %bb24.preheader.split
27+
28+
bb24.preheader.split.us: ; preds = %bb24.preheader
29+
br label %bb61.us
30+
31+
bb67.us.loopexit: ; preds = %bb65.us
32+
br label %bb75
33+
34+
bb61.us: ; preds = %bb65.us, %bb24.preheader.split.us
35+
br i1 false, label %bb65.us, label %bb81.loopexit
36+
37+
bb65.us: ; preds = %bb61.us
38+
br i1 false, label %bb61.us, label %bb67.us.loopexit
39+
40+
bb24.preheader.split: ; preds = %bb24.preheader
41+
br label %bb27
42+
43+
bb27: ; preds = %bb24.preheader.split
44+
br i1 false, label %bb42, label %bb67
45+
46+
bb42: ; preds = %bb27
47+
br label %bb19
48+
49+
bb67: ; preds = %bb27
50+
br label %bb75
51+
52+
bb75: ; preds = %bb67, %bb67.us.loopexit
53+
br i1 undef, label %bb24.preheader, label %bb84.loopexit
54+
55+
bb81.loopexit: ; preds = %bb61.us
56+
br label %bb10
57+
58+
bb84.loopexit: ; preds = %bb75
59+
ret void
60+
}
61+
62+
attributes #0 = { "target-features"="+transactional-execution,+vector" }

0 commit comments

Comments
 (0)