]> granicus.if.org Git - llvm/commitdiff
[AliasAnalysis] Give back AA results for fence instructions
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 15 Jul 2016 17:19:24 +0000 (17:19 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 15 Jul 2016 17:19:24 +0000 (17:19 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275581 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Instruction.h
lib/Analysis/AliasAnalysis.cpp
lib/Transforms/Utils/MemorySSA.cpp

index 748bb946775d7ee1d8b1c1780de693c9031d72f7..df4f8df78b121c48d07d68035845b6c354f6b860 100644 (file)
@@ -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
index ab5f814fb39f3df00a0c270efb72fab3590234f6..f931b6fc6523bca3308909b9827349de56c849b5 100644 (file)
@@ -111,6 +111,9 @@ ModRefInfo AAResults::getModRefInfo(Instruction *I, ImmutableCallSite Call) {
   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
index 0aed1334571e406d89119cc0672a6123a863c1de..f93917f986139daf5ba90cb6b53b75a1f8951541 100644 (file)
@@ -1252,7 +1252,7 @@ MemoryAccess *MemorySSA::CachingWalker::getClobberingMemoryAccess(
 
   // 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::getClobberingMemoryAccess(const Instruction *I) {
   // 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;