Skip to content

Commit ae40dfc

Browse files
committed
[MemorySSA] Update last_access_in_block check.
The check for "was there an access in this block" should be: is the last access in this block and is it not a newly inserted phi. Resolves new test in PR43438. Also fix a typo when simplifying trivial Phis to match the comment. llvm-svn: 373380
1 parent 2cee0e2 commit ae40dfc

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

llvm/lib/Analysis/MemorySSAUpdater.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,12 @@ void MemorySSAUpdater::insertDef(MemoryDef *MD, bool RenameUses) {
303303

304304
// See if we had a local def, and if not, go hunting.
305305
MemoryAccess *DefBefore = getPreviousDef(MD);
306-
bool DefBeforeSameBlock = DefBefore->getBlock() == MD->getBlock();
306+
bool DefBeforeSameBlock = false;
307+
if (DefBefore->getBlock() == MD->getBlock() &&
308+
!(isa<MemoryPhi>(DefBefore) &&
309+
std::find(InsertedPHIs.begin(), InsertedPHIs.end(), DefBefore) !=
310+
InsertedPHIs.end()))
311+
DefBeforeSameBlock = true;
307312

308313
// There is a def before us, which means we can replace any store/phi uses
309314
// of that thing with us, since we are in the way of whatever was there
@@ -628,7 +633,7 @@ void MemorySSAUpdater::updatePhisWhenInsertingUniqueBackedgeBlock(
628633

629634
// If NewMPhi is a trivial phi, remove it. Its use in the header MPhi will be
630635
// replaced with the unique value.
631-
tryRemoveTrivialPhi(MPhi);
636+
tryRemoveTrivialPhi(NewMPhi);
632637
}
633638

634639
void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks,

llvm/test/Analysis/MemorySSA/pr43438.ll

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,57 @@ if.end569: ; preds = %if.else568, %if.the
4444
ret void
4545
}
4646

47+
48+
; CHECK-LABEL: @f()
49+
; CHECK: 8 = MemoryPhi(
50+
; CHECK: 7 = MemoryPhi(
51+
; CHECK: 11 = MemoryPhi(
52+
; CHECK: 10 = MemoryPhi(
53+
; CHECK: 9 = MemoryPhi(
54+
define void @f() {
55+
entry:
56+
%e = alloca i16, align 1
57+
br label %lbl1
58+
59+
lbl1: ; preds = %if.else, %for.end5, %entry
60+
store i16 undef, i16* %e, align 1
61+
%0 = load i16, i16* %e, align 1
62+
%call = call i16 @g(i16 %0)
63+
br i1 undef, label %for.end, label %if.else
64+
65+
for.end: ; preds = %if.then
66+
br i1 true, label %for.cond2, label %lbl2
67+
68+
lbl2: ; preds = %for.body4, %if.end
69+
br label %for.cond2
70+
71+
for.cond2: ; preds = %lbl3
72+
br i1 undef, label %for.body4, label %for.end5
73+
74+
for.body4: ; preds = %for.cond2
75+
br label %lbl2
76+
77+
for.end5: ; preds = %for.cond2
78+
switch i32 undef, label %unreachable [
79+
i32 0, label %if.end12
80+
i32 2, label %lbl1
81+
]
82+
83+
if.else: ; preds = %lbl1
84+
switch i32 undef, label %unreachable [
85+
i32 0, label %if.end12
86+
i32 2, label %lbl1
87+
]
88+
89+
if.end12: ; preds = %cleanup.cont11s, %cleanup.cont
90+
call void @llvm.lifetime.end.p0i8(i64 1, i8* undef)
91+
ret void
92+
93+
unreachable: ; preds = %if.else, %for.end5
94+
unreachable
95+
}
96+
97+
declare i16 @g(i16)
98+
99+
; Function Attrs: argmemonly nounwind willreturn
100+
declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)

0 commit comments

Comments
 (0)