[llvm] r260520 - Make context-sensitive isDereferenceable queries in isSafeToLoadUnconditionally

Artur Pilipenko via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 11 05:43:00 PST 2016


Author: apilipenko
Date: Thu Feb 11 07:42:59 2016
New Revision: 260520

URL: http://llvm.org/viewvc/llvm-project?rev=260520&view=rev
Log:
Make context-sensitive isDereferenceable queries in isSafeToLoadUnconditionally

This is a part of the refactoring to unify isSafeToLoadUnconditionally and isDereferenceablePointer functions. In the subsequent change isSafeToSpeculativelyExecute will be modified to use isSafeToLoadUnconditionally instead of isDereferenceableAndAlignedPointer.   

Reviewed By: reames

Differential Revision: http://reviews.llvm.org/D16227

Modified:
    llvm/trunk/include/llvm/Analysis/Loads.h
    llvm/trunk/lib/Analysis/Loads.cpp

Modified: llvm/trunk/include/llvm/Analysis/Loads.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/Loads.h?rev=260520&r1=260519&r2=260520&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/Loads.h (original)
+++ llvm/trunk/include/llvm/Analysis/Loads.h Thu Feb 11 07:42:59 2016
@@ -24,11 +24,17 @@ class DataLayout;
 class MDNode;
 
 /// isSafeToLoadUnconditionally - Return true if we know that executing a load
-/// from this value cannot trap.  If it is not obviously safe to load from the
-/// specified pointer, we do a quick local scan of the basic block containing
-/// ScanFrom, to determine if the address is already accessed.
+/// from this value cannot trap.
+///
+/// If DT is specified this method performs context-sensitive analysis.
+///
+/// If it is not obviously safe to load from the specified pointer, we do a
+/// quick local scan of the basic block containing ScanFrom, to determine if
+/// the address is already accessed.
 bool isSafeToLoadUnconditionally(Value *V, unsigned Align,
-                                 Instruction *ScanFrom);
+                                 Instruction *ScanFrom,
+                                 const DominatorTree *DT = nullptr,
+                                 const TargetLibraryInfo *TLI = nullptr);
 
 /// DefMaxInstsToScan - the default number of maximum instructions
 /// to scan in the block, used by FindAvailableLoadedValue().

Modified: llvm/trunk/lib/Analysis/Loads.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Loads.cpp?rev=260520&r1=260519&r2=260520&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Loads.cpp (original)
+++ llvm/trunk/lib/Analysis/Loads.cpp Thu Feb 11 07:42:59 2016
@@ -56,6 +56,8 @@ static bool AreEquivalentAddressValues(c
 
 /// \brief Check if executing a load of this pointer value cannot trap.
 ///
+/// If DT is specified this method performs context-sensitive analysis.
+///
 /// If it is not obviously safe to load from the specified pointer, we do
 /// a quick local scan of the basic block containing \c ScanFrom, to determine
 /// if the address is already accessed.
@@ -63,7 +65,9 @@ static bool AreEquivalentAddressValues(c
 /// This uses the pointee type to determine how many bytes need to be safe to
 /// load from the pointer.
 bool llvm::isSafeToLoadUnconditionally(Value *V, unsigned Align,
-                                       Instruction *ScanFrom) {
+                                       Instruction *ScanFrom,
+                                       const DominatorTree *DT,
+                                       const TargetLibraryInfo *TLI) {
   const DataLayout &DL = ScanFrom->getModule()->getDataLayout();
 
   // Zero alignment means that the load has the ABI alignment for the target
@@ -71,7 +75,9 @@ bool llvm::isSafeToLoadUnconditionally(V
     Align = DL.getABITypeAlignment(V->getType()->getPointerElementType());
   assert(isPowerOf2_32(Align));
 
-  if (isDereferenceableAndAlignedPointer(V, Align, DL))
+  // If DT is not specified we can't make context-sensitive query
+  const Instruction* CtxI = DT ? ScanFrom : nullptr;
+  if (isDereferenceableAndAlignedPointer(V, Align, DL, CtxI, DT, TLI))
     return true;
 
   int64_t ByteOffset = 0;




More information about the llvm-commits mailing list