[llvm] [ValueTracking] Add support for `usub.sat` in `isKnownNonZero (PR #87700)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 4 13:36:00 PDT 2024
https://github.com/goldsteinn created https://github.com/llvm/llvm-project/pull/87700
A missed case (that we infact had tests for already).
Proof: https://alive2.llvm.org/ce/z/54zsbS
>From 969c66811ee0e1df663503e353b4381e3b7df0b4 Mon Sep 17 00:00:00 2001
From: Noah Goldstein <goldstein.w.n at gmail.com>
Date: Wed, 3 Apr 2024 15:35:57 -0500
Subject: [PATCH] [ValueTracking] Add support for `usub.sat` in `isKnownNonZero
A missed case (that we infact had tests for already).
Proof: https://alive2.llvm.org/ce/z/54zsbS
---
llvm/lib/Analysis/ValueTracking.cpp | 14 ++++++++++++++
llvm/test/Analysis/ValueTracking/known-non-zero.ll | 6 +-----
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 5ad4da43bca7db..57115a78360c1b 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2816,6 +2816,20 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
case Intrinsic::bswap:
case Intrinsic::ctpop:
return isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q);
+ case Intrinsic::usub_sat: {
+ KnownBits XKnown =
+ computeKnownBits(II->getArgOperand(0), DemandedElts, Depth, Q);
+ if (XKnown.isUnknown())
+ break;
+ KnownBits YKnown =
+ computeKnownBits(II->getArgOperand(1), DemandedElts, Depth, Q);
+ if (YKnown.isUnknown())
+ break;
+ std::optional<bool> NonZero = KnownBits::ugt(XKnown, YKnown);
+ if (NonZero.has_value())
+ return *NonZero;
+ break;
+ }
case Intrinsic::ssub_sat:
return isNonZeroSub(DemandedElts, Depth, Q, BitWidth,
II->getArgOperand(0), II->getArgOperand(1));
diff --git a/llvm/test/Analysis/ValueTracking/known-non-zero.ll b/llvm/test/Analysis/ValueTracking/known-non-zero.ll
index 0159050d925c3e..00a0c07ede9763 100644
--- a/llvm/test/Analysis/ValueTracking/known-non-zero.ll
+++ b/llvm/test/Analysis/ValueTracking/known-non-zero.ll
@@ -882,11 +882,7 @@ define i1 @usub_sat_nonzero(i8 %xx, i8 %yy, i8 %ind) {
; CHECK-LABEL: @usub_sat_nonzero(
; CHECK-NEXT: [[Y_ULT_31:%.*]] = icmp ult i8 [[YY:%.*]], 31
; CHECK-NEXT: call void @llvm.assume(i1 [[Y_ULT_31]])
-; CHECK-NEXT: [[XO:%.*]] = or i8 [[XX:%.*]], 34
-; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[XO]], i8 [[YY]])
-; 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
;
%y_ult_31 = icmp ult i8 %yy, 31
call void @llvm.assume(i1 %y_ult_31)
More information about the llvm-commits
mailing list