[llvm] r271455 - Remove Value::isPointerDereferenceable; NFCI

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 1 17:52:48 PDT 2016


Author: sanjoy
Date: Wed Jun  1 19:52:48 2016
New Revision: 271455

URL: http://llvm.org/viewvc/llvm-project?rev=271455&view=rev
Log:
Remove Value::isPointerDereferenceable; NFCI

... and merge into `Value::getPointerDereferenceableBytes`. This was
suggested by Artur Pilipenko in D20764 -- since we no longer allow loads
of unsized types, there is no need anymore to have this special logic.

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

Modified: llvm/trunk/include/llvm/IR/Value.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Value.h?rev=271455&r1=271454&r2=271455&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Value.h (original)
+++ llvm/trunk/include/llvm/IR/Value.h Wed Jun  1 19:52:48 2016
@@ -509,13 +509,8 @@ public:
   ///
   /// If CanBeNull is set by this function the pointer can either be null or be
   /// dereferenceable up to the returned number of bytes.
-  unsigned getPointerDereferenceableBytes(bool &CanBeNull) const;
-
-  /// \brief Returns true if the pointer value is fully dereferenceable.
-  ///
-  /// Sets CanBeNull to true if the pointer is either null or can be fully
-  /// dereferenceable.
-  bool isPointerDereferenceable(bool &CanBeNull) const;
+  unsigned getPointerDereferenceableBytes(const DataLayout &DL,
+                                          bool &CanBeNull) const;
 
   /// \brief Returns an alignment of the pointer value.
   ///

Modified: llvm/trunk/lib/Analysis/Loads.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Loads.cpp?rev=271455&r1=271454&r2=271455&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Loads.cpp (original)
+++ llvm/trunk/lib/Analysis/Loads.cpp Wed Jun  1 19:52:48 2016
@@ -32,7 +32,7 @@ static bool isDereferenceableFromAttribu
                                            const TargetLibraryInfo *TLI) {
   bool CheckForNonNull = false;
   APInt DerefBytes(Size.getBitWidth(),
-                   BV->getPointerDereferenceableBytes(CheckForNonNull));
+                   BV->getPointerDereferenceableBytes(DL, CheckForNonNull));
 
   if (DerefBytes.getBoolValue())
     if (DerefBytes.uge(Size))
@@ -75,16 +75,6 @@ static bool isDereferenceableAndAlignedP
   // Note that it is not safe to speculate into a malloc'd region because
   // malloc may return null.
 
-  bool CheckForNonNull;
-  if (V->isPointerDereferenceable(CheckForNonNull)) {
-    Type *ETy = V->getType()->getPointerElementType();
-    if (ETy->isSized() && Size.ule(DL.getTypeStoreSize(ETy))) {
-      if (CheckForNonNull && !isKnownNonNullAt(V, CtxI, DT, TLI))
-        return false;
-      return isAligned(V, Align, DL);
-    }
-  }
-
   // bitcast instructions are no-ops as far as dereferenceability is concerned.
   if (const BitCastOperator *BC = dyn_cast<BitCastOperator>(V))
     return isDereferenceableAndAlignedPointer(BC->getOperand(0), Align, Size,

Modified: llvm/trunk/lib/IR/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=271455&r1=271454&r2=271455&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Value.cpp (original)
+++ llvm/trunk/lib/IR/Value.cpp Wed Jun  1 19:52:48 2016
@@ -525,13 +525,18 @@ Value *Value::stripInBoundsOffsets() {
   return stripPointerCastsAndOffsets<PSK_InBounds>(this);
 }
 
-unsigned Value::getPointerDereferenceableBytes(bool &CanBeNull) const {
+unsigned Value::getPointerDereferenceableBytes(const DataLayout &DL,
+                                               bool &CanBeNull) const {
   assert(getType()->isPointerTy() && "must be pointer");
 
   unsigned DerefBytes = 0;
   CanBeNull = false;
   if (const Argument *A = dyn_cast<Argument>(this)) {
     DerefBytes = A->getDereferenceableBytes();
+    if (DerefBytes == 0 && A->hasByValAttr() && A->getType()->isSized()) {
+      DerefBytes = DL.getTypeStoreSize(A->getType());
+      CanBeNull = false;
+    }
     if (DerefBytes == 0) {
       DerefBytes = A->getDereferenceableOrNullBytes();
       CanBeNull = true;
@@ -555,33 +560,22 @@ unsigned Value::getPointerDereferenceabl
       }
       CanBeNull = true;
     }
+  } else if (auto *AI = dyn_cast<AllocaInst>(this)) {
+    if (AI->getAllocatedType()->isSized()) {
+      DerefBytes = DL.getTypeStoreSize(AI->getAllocatedType());
+      CanBeNull = false;
+    }
+  } else if (auto *GV = dyn_cast<GlobalVariable>(this)) {
+    if (GV->getValueType()->isSized() && !GV->hasExternalWeakLinkage()) {
+      // TODO: Don't outright reject hasExternalWeakLinkage but set the
+      // CanBeNull flag.
+      DerefBytes = DL.getTypeStoreSize(GV->getValueType());
+      CanBeNull = false;
+    }
   }
   return DerefBytes;
 }
 
-bool Value::isPointerDereferenceable(bool &CanBeNull) const {
-  assert(getType()->isPointerTy() && "must be pointer");
-
-  CanBeNull = false;
-
-  // These are obviously ok.
-  if (isa<AllocaInst>(this))
-    return true;
-
-  // Global variables which can't collapse to null are ok.
-  // TODO: return true for those but set CanBeNull flag
-  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
-    if (!GV->hasExternalWeakLinkage())
-      return true;
-
-  // byval arguments are okay.
-  if (const Argument *A = dyn_cast<Argument>(this))
-    if (A->hasByValAttr())
-      return true;
-
-  return false;
-}
-
 unsigned Value::getPointerAlignment(const DataLayout &DL) const {
   assert(getType()->isPointerTy() && "must be pointer");
 




More information about the llvm-commits mailing list