[PATCH] D34165: [ValueTracking] Correct early out in computeKnownBitsFromOperator to work with non power of 2 bit widths

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 13 13:27:56 PDT 2017


craig.topper created this revision.

There's an early out that's trying to detect when we don't know any bits that make up the legal range of a shift. The code subtracts one from BitWidth which creates a mask in the lower bits for power of 2 bit widths. This is then ANDed with the known bits to see if any of those bits are known. If the bit width isn't a power of 2 this creates a non-sensical mask.

This patch corrects this by rounding up to a power of 2 before doing the subtract and mask.

I found this by inspection. I'll try to put together a test, but wanted to make sure others agreed with my assessment.


https://reviews.llvm.org/D34165

Files:
  lib/Analysis/ValueTracking.cpp


Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -852,7 +852,8 @@
   Optional<bool> ShifterOperandIsNonZero;
 
   // Early exit if we can't constrain any well-defined shift amount.
-  if (!(ShiftAmtKZ & (BitWidth - 1)) && !(ShiftAmtKO & (BitWidth - 1))) {
+  if (!(ShiftAmtKZ & (PowerOf2Ceil(BitWidth) - 1)) &&
+      !(ShiftAmtKO & (PowerOf2Ceil(BitWidth) - 1))) {
     ShifterOperandIsNonZero =
         isKnownNonZero(I->getOperand(1), Depth + 1, Q);
     if (!*ShifterOperandIsNonZero)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34165.102391.patch
Type: text/x-patch
Size: 620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170613/ceaa9c73/attachment.bin>


More information about the llvm-commits mailing list