<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
This is a non-functional refactoring of existing code, namely extracting a function out of existing code. This function is triggered by any dereferenceability test. Am I missing something? 
<div class=""><br class="">
</div>
<div class="">Artur</div>
<div class=""><br class="">
<div>
<blockquote type="cite" class="">
<div class="">On 27 Apr 2016, at 21:10, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">It's generally good to not checkin entirely dead & untested code - could you include a unit test to demonstrate correctness, at least?</div>
<div class="gmail_extra"><br class="">
<div class="gmail_quote">On Wed, Apr 27, 2016 at 5:51 AM, Artur Pilipenko via llvm-commits
<span dir="ltr" class=""><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>></span> wrote:<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: apilipenko<br class="">
Date: Wed Apr 27 07:51:01 2016<br class="">
New Revision: 267708<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=267708&view=rev" rel="noreferrer" target="_blank" class="">
http://llvm.org/viewvc/llvm-project?rev=267708&view=rev</a><br class="">
Log:<br class="">
NFC. Introduce Value::getPointerDerferecnceableBytes<br class="">
<br class="">
Extract a part of isDereferenceableAndAlignedPointer functionality to Value::getPointerDerferecnceableBytes. Currently it's a NFC, but in future I'm going to accumulate all the logic about value dereferenceability in this function similarly to Value::getPointerAlignment
 function (D16144).<br class="">
<br class="">
Reviewed By: reames<br class="">
<br class="">
Differential Revision: <a href="http://reviews.llvm.org/D17572" rel="noreferrer" target="_blank" class="">
http://reviews.llvm.org/D17572</a><br class="">
<br class="">
Modified:<br class="">
    llvm/trunk/include/llvm/IR/Value.h<br class="">
    llvm/trunk/lib/Analysis/Loads.cpp<br class="">
    llvm/trunk/lib/IR/Value.cpp<br class="">
<br class="">
Modified: llvm/trunk/include/llvm/IR/Value.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Value.h?rev=267708&r1=267707&r2=267708&view=diff" rel="noreferrer" target="_blank" class="">
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Value.h?rev=267708&r1=267707&r2=267708&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/include/llvm/IR/Value.h (original)<br class="">
+++ llvm/trunk/include/llvm/IR/Value.h Wed Apr 27 07:51:01 2016<br class="">
@@ -504,6 +504,13 @@ public:<br class="">
     return const_cast<Value*>(this)->stripInBoundsOffsets();<br class="">
   }<br class="">
<br class="">
+  /// \brief Returns the number of bytes known to be dereferenceable for the<br class="">
+  /// pointer value.<br class="">
+  ///<br class="">
+  /// If CanBeNull is set by this function the pointer can either be null or be<br class="">
+  /// dereferenceable up to the returned number of bytes.<br class="">
+  unsigned getPointerDereferenceableBytes(bool &CanBeNull) const;<br class="">
+<br class="">
   /// \brief Returns an alignment of the pointer value.<br class="">
   ///<br class="">
   /// Returns an alignment which is either specified explicitly, e.g. via<br class="">
<br class="">
Modified: llvm/trunk/lib/Analysis/Loads.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Loads.cpp?rev=267708&r1=267707&r2=267708&view=diff" rel="noreferrer" target="_blank" class="">
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Loads.cpp?rev=267708&r1=267707&r2=267708&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/lib/Analysis/Loads.cpp (original)<br class="">
+++ llvm/trunk/lib/Analysis/Loads.cpp Wed Apr 27 07:51:01 2016<br class="">
@@ -33,34 +33,9 @@ static bool isDereferenceableFromAttribu<br class="">
   assert(Offset.isNonNegative() && "offset can't be negative");<br class="">
   assert(Ty->isSized() && "must be sized");<br class="">
<br class="">
-  APInt DerefBytes(Offset.getBitWidth(), 0);<br class="">
   bool CheckForNonNull = false;<br class="">
-  if (const Argument *A = dyn_cast<Argument>(BV)) {<br class="">
-    DerefBytes = A->getDereferenceableBytes();<br class="">
-    if (!DerefBytes.getBoolValue()) {<br class="">
-      DerefBytes = A->getDereferenceableOrNullBytes();<br class="">
-      CheckForNonNull = true;<br class="">
-    }<br class="">
-  } else if (auto CS = ImmutableCallSite(BV)) {<br class="">
-    DerefBytes = CS.getDereferenceableBytes(0);<br class="">
-    if (!DerefBytes.getBoolValue()) {<br class="">
-      DerefBytes = CS.getDereferenceableOrNullBytes(0);<br class="">
-      CheckForNonNull = true;<br class="">
-    }<br class="">
-  } else if (const LoadInst *LI = dyn_cast<LoadInst>(BV)) {<br class="">
-    if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {<br class="">
-      ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));<br class="">
-      DerefBytes = CI->getLimitedValue();<br class="">
-    }<br class="">
-    if (!DerefBytes.getBoolValue()) {<br class="">
-      if (MDNode *MD =<br class="">
-              LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {<br class="">
-        ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));<br class="">
-        DerefBytes = CI->getLimitedValue();<br class="">
-      }<br class="">
-      CheckForNonNull = true;<br class="">
-    }<br class="">
-  }<br class="">
+  APInt DerefBytes(Offset.getBitWidth(),<br class="">
+                   BV->getPointerDereferenceableBytes(CheckForNonNull));<br class="">
<br class="">
   if (DerefBytes.getBoolValue())<br class="">
     if (DerefBytes.uge(Offset + DL.getTypeStoreSize(Ty)))<br class="">
<br class="">
Modified: llvm/trunk/lib/IR/Value.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=267708&r1=267707&r2=267708&view=diff" rel="noreferrer" target="_blank" class="">
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=267708&r1=267707&r2=267708&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/lib/IR/Value.cpp (original)<br class="">
+++ llvm/trunk/lib/IR/Value.cpp Wed Apr 27 07:51:01 2016<br class="">
@@ -525,6 +525,40 @@ Value *Value::stripInBoundsOffsets() {<br class="">
   return stripPointerCastsAndOffsets<PSK_InBounds>(this);<br class="">
 }<br class="">
<br class="">
+unsigned Value::getPointerDereferenceableBytes(bool &CanBeNull) const {<br class="">
+  assert(getType()->isPointerTy() && "must be pointer");<br class="">
+<br class="">
+  unsigned DerefBytes = 0;<br class="">
+  CanBeNull = false;<br class="">
+  if (const Argument *A = dyn_cast<Argument>(this)) {<br class="">
+    DerefBytes = A->getDereferenceableBytes();<br class="">
+    if (DerefBytes == 0) {<br class="">
+      DerefBytes = A->getDereferenceableOrNullBytes();<br class="">
+      CanBeNull = true;<br class="">
+    }<br class="">
+  } else if (auto CS = ImmutableCallSite(this)) {<br class="">
+    DerefBytes = CS.getDereferenceableBytes(0);<br class="">
+    if (DerefBytes == 0) {<br class="">
+      DerefBytes = CS.getDereferenceableOrNullBytes(0);<br class="">
+      CanBeNull = true;<br class="">
+    }<br class="">
+  } else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {<br class="">
+    if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {<br class="">
+      ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));<br class="">
+      DerefBytes = CI->getLimitedValue();<br class="">
+    }<br class="">
+    if (DerefBytes == 0) {<br class="">
+      if (MDNode *MD =<br class="">
+              LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {<br class="">
+        ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));<br class="">
+        DerefBytes = CI->getLimitedValue();<br class="">
+      }<br class="">
+      CanBeNull = true;<br class="">
+    }<br class="">
+  }<br class="">
+  return DerefBytes;<br class="">
+}<br class="">
+<br class="">
 unsigned Value::getPointerAlignment(const DataLayout &DL) const {<br class="">
   assert(getType()->isPointerTy() && "must be pointer");<br class="">
<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="">
</blockquote>
</div>
<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>