[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 23:50:25 PDT 2017


craig.topper updated this revision to Diff 102490.
craig.topper added a comment.

Fix formatting


https://reviews.llvm.org/D34165

Files:
  lib/Analysis/ValueTracking.cpp
  test/Transforms/InstCombine/shift.ll


Index: test/Transforms/InstCombine/shift.ll
===================================================================
--- test/Transforms/InstCombine/shift.ll
+++ test/Transforms/InstCombine/shift.ll
@@ -1306,3 +1306,12 @@
   ret <2 x i8> %shr
 }
 
+define i7 @test65(i7 %a, i7 %b) {
+; CHECK-LABEL: @test65(
+; CHECK-NEXT:    ret i7 0
+;
+  %shiftamt = and i7 %b, 6
+  %x = lshr i7 42, %shiftamt
+  %y = and i7 %x, 1
+  ret i7 %y
+}
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.102490.patch
Type: text/x-patch
Size: 1048 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170614/06b04aa0/attachment.bin>


More information about the llvm-commits mailing list