[PATCH] D149410: [ValueTracking] Add logic for `isKnownNonZero(ctlz/cttz X)`

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 29 15:06:58 PDT 2023


goldstein.w.n updated this revision to Diff 518244.
goldstein.w.n added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149410/new/

https://reviews.llvm.org/D149410

Files:
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/test/Analysis/ValueTracking/known-non-zero.ll


Index: llvm/test/Analysis/ValueTracking/known-non-zero.ll
===================================================================
--- llvm/test/Analysis/ValueTracking/known-non-zero.ll
+++ llvm/test/Analysis/ValueTracking/known-non-zero.ll
@@ -693,11 +693,7 @@
 
 define i1 @ctlz_true_nonzero(i8 %xx, i8 %ind) {
 ; CHECK-LABEL: @ctlz_true_nonzero(
-; CHECK-NEXT:    [[XS:%.*]] = lshr i8 [[XX:%.*]], 1
-; CHECK-NEXT:    [[X:%.*]] = call i8 @llvm.ctlz.i8(i8 [[XS]], i1 true)
-; CHECK-NEXT:    [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
-; CHECK-NEXT:    [[R:%.*]] = icmp eq i8 [[Z]], 0
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 false
 ;
   %xs = lshr i8 %xx, 1
   %x = call i8 @llvm.ctlz.i8(i8 %xs, i1 true)
@@ -708,11 +704,7 @@
 
 define i1 @ctlz_false_nonzero(i8 %xx, i8 %ind) {
 ; CHECK-LABEL: @ctlz_false_nonzero(
-; CHECK-NEXT:    [[XA:%.*]] = and i8 [[XX:%.*]], 127
-; CHECK-NEXT:    [[X:%.*]] = call i8 @llvm.ctlz.i8(i8 [[XA]], i1 true)
-; CHECK-NEXT:    [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
-; CHECK-NEXT:    [[R:%.*]] = icmp eq i8 [[Z]], 0
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 false
 ;
   %xa = and i8 %xx, 127
   %x = call i8 @llvm.ctlz.i8(i8 %xa, i1 true)
@@ -738,11 +730,7 @@
 
 define i1 @cttz_true_nonzero(i8 %xx, i8 %ind) {
 ; CHECK-LABEL: @cttz_true_nonzero(
-; CHECK-NEXT:    [[XS:%.*]] = shl i8 [[XX:%.*]], 1
-; CHECK-NEXT:    [[X:%.*]] = call i8 @llvm.cttz.i8(i8 [[XS]], i1 true)
-; CHECK-NEXT:    [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
-; CHECK-NEXT:    [[R:%.*]] = icmp eq i8 [[Z]], 0
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 false
 ;
   %xs = shl i8 %xx, 1
   %x = call i8 @llvm.cttz.i8(i8 %xs, i1 true)
@@ -753,11 +741,7 @@
 
 define i1 @cttz_false_nonzero(i8 %xx, i8 %ind) {
 ; CHECK-LABEL: @cttz_false_nonzero(
-; CHECK-NEXT:    [[XA:%.*]] = and i8 [[XX:%.*]], -2
-; CHECK-NEXT:    [[X:%.*]] = call i8 @llvm.cttz.i8(i8 [[XA]], i1 true)
-; CHECK-NEXT:    [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
-; CHECK-NEXT:    [[R:%.*]] = icmp eq i8 [[Z]], 0
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 false
 ;
   %xa = and i8 %xx, -2
   %x = call i8 @llvm.cttz.i8(i8 %xa, i1 true)
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2932,6 +2932,12 @@
             isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q))
           return true;
         break;
+      case Intrinsic::cttz:
+        return computeKnownBits(II->getArgOperand(0), DemandedElts, Depth, Q)
+            .Zero[0];
+      case Intrinsic::ctlz:
+        return computeKnownBits(II->getArgOperand(0), DemandedElts, Depth, Q)
+            .isNonNegative();
       case Intrinsic::fshr:
       case Intrinsic::fshl:
         // If Op0 == Op1, this is a rotate. rotate(x, y) != 0 iff x != 0.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149410.518244.patch
Type: text/x-patch
Size: 2868 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230429/7c034756/attachment.bin>


More information about the llvm-commits mailing list