Skip to content

Commit 6b2d134

Browse files
committed
[MemorySSA] Update MSSA for non-conventional AA.
Summary: Regularly when moving an instruction that may not read or write memory, the instruction is not modelled in MSSA, so not action is necessary. For a non-conventional AA pipeline, MSSA needs to explicitly check when creating accesses, so as to not model instructions that may not read and write memory. Reviewers: george.burgess.iv Subscribers: Prazek, sanjoy.google, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67562 llvm-svn: 372137
1 parent 39c5106 commit 6b2d134

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

llvm/lib/Analysis/MemorySSA.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,9 +1736,15 @@ MemoryUseOrDef *MemorySSA::createNewAccess(Instruction *I,
17361736
// FIXME: Replace this special casing with a more accurate modelling of
17371737
// assume's control dependency.
17381738
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I))
1739-
if (II->getIntrinsicID() == Intrinsic::assume || isa<DbgInfoIntrinsic>(II))
1739+
if (II->getIntrinsicID() == Intrinsic::assume)
17401740
return nullptr;
17411741

1742+
// Using a nonstandard AA pipelines might leave us with unexpected modref
1743+
// results for I, so add a check to not model instructions that may not read
1744+
// from or write to memory. This is necessary for correctness.
1745+
if (!I->mayReadFromMemory() && !I->mayWriteToMemory())
1746+
return nullptr;
1747+
17421748
bool Def, Use;
17431749
if (Template) {
17441750
Def = dyn_cast_or_null<MemoryDef>(Template) != nullptr;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: opt -disable-basicaa -print-memoryssa -disable-output %s 2>&1 | FileCheck %s
2+
3+
; Note: if @foo is modelled as a MemoryDef, this test will assert with -loop-rotate, due to MemorySSA not
4+
; being preserved when moving instructions that may not read from or write to memory.
5+
6+
; CHECK-LABEL: @main
7+
; CHECK-NOT: MemoryDef
8+
define void @main() {
9+
entry:
10+
br label %for.cond120
11+
12+
for.cond120: ; preds = %for.body127, %entry
13+
call void @foo()
14+
br i1 undef, label %for.body127, label %for.cond.cleanup126
15+
16+
for.cond.cleanup126: ; preds = %for.cond120
17+
unreachable
18+
19+
for.body127: ; preds = %for.cond120
20+
%0 = load i16**, i16*** undef, align 1
21+
br label %for.cond120
22+
}
23+
24+
declare void @foo() readnone
25+
26+

0 commit comments

Comments
 (0)