[llvm] r251380 - [ValueTracking] Don't special case wrapped ConstantRanges; NFCI

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 26 18:36:07 PDT 2015


Author: sanjoy
Date: Mon Oct 26 20:36:06 2015
New Revision: 251380

URL: http://llvm.org/viewvc/llvm-project?rev=251380&view=rev
Log:
[ValueTracking] Don't special case wrapped ConstantRanges; NFCI

Use `getUnsignedMax` directly instead of special casing a wrapped
ConstantRange.

The previous code would have been "buggy" (and this would have been a
semantic change) if LLVM allowed !range metadata to denote full
ranges. E.g. in

  %val = load i1, i1* %ptr, !range !{i1 1, i1 1} ;; == full set

ValueTracking would conclude that the high bit (IOW the only bit) in
%val was zero.

Since !range metadata does not allow empty or full ranges, this change
is just a minor stylistic improvement.

Modified:
    llvm/trunk/lib/Analysis/ValueTracking.cpp

Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=251380&r1=251379&r2=251380&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Mon Oct 26 20:36:06 2015
@@ -380,9 +380,7 @@ void llvm::computeKnownBitsFromRangeMeta
     ConstantInt *Upper =
         mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 1));
     ConstantRange Range(Lower->getValue(), Upper->getValue());
-    if (Range.isWrappedSet())
-      MinLeadingZeros = 0; // -1 has no zeros
-    unsigned LeadingZeros = (Upper->getValue() - 1).countLeadingZeros();
+    unsigned LeadingZeros = Range.getUnsignedMax().countLeadingZeros();
     MinLeadingZeros = std::min(LeadingZeros, MinLeadingZeros);
   }
 




More information about the llvm-commits mailing list