[PATCH] D128217: [ValueTracking] Teach isKnownNonZero that a vscale is never 0.

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 20 11:14:59 PDT 2022


dmgreen created this revision.
dmgreen added reviewers: spatel, nikic, paulwalker-arm, david-arm, efriedma.
Herald added a subscriber: hiraditya.
Herald added a project: All.
dmgreen requested review of this revision.
Herald added a project: LLVM.

A llvm.vscale will always be at least 1, never zero. Teaching that to isKnownNonZero can help fold away some statically known compares.


https://reviews.llvm.org/D128217

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


Index: llvm/test/Transforms/InstCombine/vscale_zero.ll
===================================================================
--- llvm/test/Transforms/InstCombine/vscale_zero.ll
+++ llvm/test/Transforms/InstCombine/vscale_zero.ll
@@ -4,9 +4,7 @@
 define i1 @iszero() {
 ; CHECK-LABEL: @iszero(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @llvm.vscale.i32()
-; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[TMP0]], 0
-; CHECK-NEXT:    ret i1 [[TMP1]]
+; CHECK-NEXT:    ret i1 false
 ;
   entry:
   %0 = call i32 @llvm.vscale.i32()
@@ -17,9 +15,7 @@
 define i1 @iszero_range() vscale_range(1,16) {
 ; CHECK-LABEL: @iszero_range(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @llvm.vscale.i32()
-; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[TMP0]], 0
-; CHECK-NEXT:    ret i1 [[TMP1]]
+; CHECK-NEXT:    ret i1 false
 ;
   entry:
   %0 = call i32 @llvm.vscale.i32()
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2698,6 +2698,9 @@
     if (isKnownNonZero(Op, Depth, Q) &&
         isGuaranteedNotToBePoison(Op, Q.AC, Q.CxtI, Q.DT, Depth))
       return true;
+  } else if (const auto *II = dyn_cast<IntrinsicInst>(V)) {
+    if (II->getIntrinsicID() == Intrinsic::vscale)
+      return true;
   }
 
   KnownBits Known(BitWidth);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128217.438439.patch
Type: text/x-patch
Size: 1409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220620/09aab682/attachment.bin>


More information about the llvm-commits mailing list