[llvm] r269190 - NFC. Introduce Value::isPointerDereferenceable
Artur Pilipenko via llvm-commits
llvm-commits at lists.llvm.org
Wed May 11 07:43:29 PDT 2016
Author: apilipenko
Date: Wed May 11 09:43:28 2016
New Revision: 269190
URL: http://llvm.org/viewvc/llvm-project?rev=269190&view=rev
Log:
NFC. Introduce Value::isPointerDereferenceable
Extract a part of isDereferenceableAndAlignedPointer functionality to Value:
Reviewed By: hfinkel, sanjoy
Differential Revision: http://reviews.llvm.org/D17611
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=269190&r1=269189&r2=269190&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Value.h (original)
+++ llvm/trunk/include/llvm/IR/Value.h Wed May 11 09:43:28 2016
@@ -511,6 +511,12 @@ public:
/// 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;
+
/// \brief Returns an alignment of the pointer value.
///
/// Returns an alignment which is either specified explicitly, e.g. via
Modified: llvm/trunk/lib/Analysis/Loads.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Loads.cpp?rev=269190&r1=269189&r2=269190&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Loads.cpp (original)
+++ llvm/trunk/lib/Analysis/Loads.cpp Wed May 11 09:43:28 2016
@@ -91,9 +91,12 @@ static bool isDereferenceableAndAlignedP
// Note that it is not safe to speculate into a malloc'd region because
// malloc may return null.
- // These are obviously ok if aligned.
- if (isa<AllocaInst>(V))
+ bool CheckForNonNull;
+ if (V->isPointerDereferenceable(CheckForNonNull)) {
+ if (CheckForNonNull && !isKnownNonNullAt(V, CtxI, DT, TLI))
+ return false;
return isAligned(V, Align, DL);
+ }
// It's not always safe to follow a bitcast, for example:
// bitcast i8* (alloca i8) to i32*
@@ -112,16 +115,6 @@ static bool isDereferenceableAndAlignedP
CtxI, DT, TLI, Visited);
}
- // Global variables which can't collapse to null are ok.
- if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
- if (!GV->hasExternalWeakLinkage())
- return isAligned(V, Align, DL);
-
- // byval arguments are okay.
- if (const Argument *A = dyn_cast<Argument>(V))
- if (A->hasByValAttr())
- return isAligned(V, Align, DL);
-
if (isDereferenceableFromAttribute(V, DL, CtxI, DT, TLI))
return isAligned(V, Align, DL);
Modified: llvm/trunk/lib/IR/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=269190&r1=269189&r2=269190&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Value.cpp (original)
+++ llvm/trunk/lib/IR/Value.cpp Wed May 11 09:43:28 2016
@@ -559,6 +559,29 @@ unsigned Value::getPointerDereferenceabl
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