[llvm] r275581 - [AliasAnalysis] Give back AA results for fence instructions
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 15 10:19:24 PDT 2016
Author: majnemer
Date: Fri Jul 15 12:19:24 2016
New Revision: 275581
URL: http://llvm.org/viewvc/llvm-project?rev=275581&view=rev
Log:
[AliasAnalysis] Give back AA results for fence instructions
Calling getModRefInfo with a fence resulted in crashes because fences
don't have a memory location. Add a new predicate to Instruction
called isFenceLike which indicates that the instruction mutates memory
but not any single memory location in particular. In practice, it is a
proxy for the set of instructions which "mayWriteToMemory" but cannot be
used with MemoryLocation::get.
This fixes PR28570.
Modified:
llvm/trunk/include/llvm/IR/Instruction.h
llvm/trunk/lib/Analysis/AliasAnalysis.cpp
llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp
Modified: llvm/trunk/include/llvm/IR/Instruction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instruction.h?rev=275581&r1=275580&r2=275581&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instruction.h (original)
+++ llvm/trunk/include/llvm/IR/Instruction.h Fri Jul 15 12:19:24 2016
@@ -399,6 +399,23 @@ public:
/// Return true if this instruction may throw an exception.
bool mayThrow() const;
+ /// Return true if this instruction behaves like a memory fence: it can load
+ /// or store to memory location without being given a memory location.
+ bool isFenceLike() const {
+ switch (getOpcode()) {
+ default:
+ return false;
+ // This list should be kept in sync with the list in mayWriteToMemory for
+ // all opcodes which don't have a memory location.
+ case Instruction::Fence:
+ case Instruction::CatchPad:
+ case Instruction::CatchRet:
+ case Instruction::Call:
+ case Instruction::Invoke:
+ return true;
+ }
+ }
+
/// Return true if the instruction may have side effects.
///
/// Note that this does not consider malloc and alloca to have side
Modified: llvm/trunk/lib/Analysis/AliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AliasAnalysis.cpp?rev=275581&r1=275580&r2=275581&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/AliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/AliasAnalysis.cpp Fri Jul 15 12:19:24 2016
@@ -111,6 +111,9 @@ ModRefInfo AAResults::getModRefInfo(Inst
if (auto CS = ImmutableCallSite(I)) {
// Check if the two calls modify the same memory
return getModRefInfo(CS, Call);
+ } else if (I->isFenceLike()) {
+ // If this is a fence, just return MRI_ModRef.
+ return MRI_ModRef;
} else {
// Otherwise, check if the call modifies or references the
// location this memory access defines. The best we can say
Modified: llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp?rev=275581&r1=275580&r2=275581&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp Fri Jul 15 12:19:24 2016
@@ -1252,7 +1252,7 @@ MemoryAccess *MemorySSA::CachingWalker::
// Conservatively, fences are always clobbers, so don't perform the walk if we
// hit a fence.
- if (isa<FenceInst>(I))
+ if (!ImmutableCallSite(I) && I->isFenceLike())
return StartingUseOrDef;
UpwardsMemoryQuery Q;
@@ -1287,15 +1287,17 @@ MemorySSA::CachingWalker::getClobberingM
// access, since we only map BB's to PHI's. So, this must be a use or def.
auto *StartingAccess = cast<MemoryUseOrDef>(MSSA->getMemoryAccess(I));
- // We can't sanely do anything with a FenceInst, they conservatively
+ bool IsCall = bool(ImmutableCallSite(I));
+
+ // We can't sanely do anything with a fences, they conservatively
// clobber all memory, and have no locations to get pointers from to
- // try to disambiguate
- if (isa<FenceInst>(I))
+ // try to disambiguate.
+ if (!IsCall && I->isFenceLike())
return StartingAccess;
UpwardsMemoryQuery Q;
Q.OriginalAccess = StartingAccess;
- Q.IsCall = bool(ImmutableCallSite(I));
+ Q.IsCall = IsCall;
if (!Q.IsCall)
Q.StartingLoc = MemoryLocation::get(I);
Q.Inst = I;
More information about the llvm-commits
mailing list