Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 5c78f7d

Browse files
committed
MemorySSA: Revert r269678 and r268068; replace with special casing in MemorySSA.
It turns out that too many passes are relying on alias analysis results for control dependencies. Until we fix that by introducing a more accurate modelling of control dependencies, special case assume in MemorySSA instead. Also introduce tests to ensure we don't regress the FunctionAttrs or LICM passes. Differential Revision: http://reviews.llvm.org/D20658 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270823 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c1beab6 commit 5c78f7d

File tree

5 files changed

+47
-9
lines changed

5 files changed

+47
-9
lines changed

lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -580,20 +580,11 @@ FunctionModRefBehavior BasicAAResult::getModRefBehavior(ImmutableCallSite CS) {
580580

581581
/// Returns the behavior when calling the given function. For use when the call
582582
/// site is not known.
583-
/// NOTE: Because of the special case handling of llvm.assume below, the result
584-
/// of this function may not match similar results derived from function
585-
/// attributes (e.g. "readnone").
586583
FunctionModRefBehavior BasicAAResult::getModRefBehavior(const Function *F) {
587584
// If the function declares it doesn't access memory, we can't do better.
588585
if (F->doesNotAccessMemory())
589586
return FMRB_DoesNotAccessMemory;
590587

591-
// While the assume intrinsic is marked as arbitrarily writing so that
592-
// proper control dependencies will be maintained, it never aliases any
593-
// actual memory locations.
594-
if (F->getIntrinsicID() == Intrinsic::assume)
595-
return FMRB_DoesNotAccessMemory;
596-
597588
FunctionModRefBehavior Min = FMRB_UnknownModRefBehavior;
598589

599590
// If the function declares it only reads memory, go with that.

lib/Transforms/Utils/MemorySSA.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,14 @@ MemorySSAWalker *MemorySSA::buildMemorySSA(AliasAnalysis *AA,
354354

355355
/// \brief Helper function to create new memory accesses
356356
MemoryUseOrDef *MemorySSA::createNewAccess(Instruction *I) {
357+
// The assume intrinsic has a control dependency which we model by claiming
358+
// that it writes arbitrarily. Ignore that fake memory dependency here.
359+
// FIXME: Replace this special casing with a more accurate modelling of
360+
// assume's control dependency.
361+
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I))
362+
if (II->getIntrinsicID() == Intrinsic::assume)
363+
return nullptr;
364+
357365
// Find out what affect this instruction has on memory.
358366
ModRefInfo ModRef = AA->getModRefInfo(I);
359367
bool Def = bool(ModRef & MRI_Mod);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; RUN: opt -S -o - -functionattrs %s | FileCheck %s
2+
3+
; CHECK-NOT: readnone
4+
declare void @llvm.assume(i1)

test/Transforms/LICM/assume.ll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
; RUN: opt -licm -basicaa < %s -S | FileCheck %s
2+
3+
define void @f(i1 %p) nounwind ssp {
4+
entry:
5+
br label %for.body
6+
7+
for.body:
8+
br i1 undef, label %if.then, label %for.cond.backedge
9+
10+
for.cond.backedge:
11+
br i1 undef, label %for.end104, label %for.body
12+
13+
if.then:
14+
br i1 undef, label %if.then27, label %if.end.if.end.split_crit_edge.critedge
15+
16+
if.then27:
17+
; CHECK: tail call void @llvm.assume
18+
tail call void @llvm.assume(i1 %p)
19+
br label %for.body61.us
20+
21+
if.end.if.end.split_crit_edge.critedge:
22+
br label %for.body61
23+
24+
for.body61.us:
25+
br i1 undef, label %for.cond.backedge, label %for.body61.us
26+
27+
for.body61:
28+
br i1 undef, label %for.cond.backedge, label %for.body61
29+
30+
for.end104:
31+
ret void
32+
}
33+
34+
declare void @llvm.assume(i1)

test/Transforms/Util/MemorySSA/assume.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ define i32 @foo(i32* %a, i32* %b, i1 %c) {
88
; CHECK: 1 = MemoryDef(liveOnEntry)
99
; CHECK-NEXT: store i32 4
1010
store i32 4, i32* %a, align 4
11+
; CHECK-NOT: MemoryDef
1112
; CHECK: call void @llvm.assume
1213
call void @llvm.assume(i1 %c)
1314
; CHECK: MemoryUse(1)

0 commit comments

Comments
 (0)