[llvm] dfda65c - [ValueTracking] Add support for non-splat vecs in cmpExcludesZero
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 12 14:05:32 PDT 2023
Author: Noah Goldstein
Date: 2023-10-12T16:05:19-05:00
New Revision: dfda65c89272eb90c0377f6c15ad134fc902dab6
URL: https://github.com/llvm/llvm-project/commit/dfda65c89272eb90c0377f6c15ad134fc902dab6
DIFF: https://github.com/llvm/llvm-project/commit/dfda65c89272eb90c0377f6c15ad134fc902dab6.diff
LOG: [ValueTracking] Add support for non-splat vecs in cmpExcludesZero
Just a small QOL change.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Analysis/ValueTracking/known-non-zero.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 11b39751b542f15..2b0bbe6f1f434bb 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -567,11 +567,24 @@ static bool cmpExcludesZero(CmpInst::Predicate Pred, const Value *RHS) {
// All other predicates - rely on generic ConstantRange handling.
const APInt *C;
- if (!match(RHS, m_APInt(C)))
+ auto Zero = APInt::getZero(RHS->getType()->getScalarSizeInBits());
+ if (match(RHS, m_APInt(C))) {
+ ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(Pred, *C);
+ return !TrueValues.contains(Zero);
+ }
+
+ auto *VC = dyn_cast<ConstantDataVector>(RHS);
+ if (VC == nullptr)
return false;
- ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(Pred, *C);
- return !TrueValues.contains(APInt::getZero(C->getBitWidth()));
+ for (unsigned ElemIdx = 0, NElem = VC->getNumElements(); ElemIdx < NElem;
+ ++ElemIdx) {
+ ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(
+ Pred, VC->getElementAsAPInt(ElemIdx));
+ if (TrueValues.contains(Zero))
+ return false;
+ }
+ return true;
}
static bool isKnownNonZeroFromAssume(const Value *V, const SimplifyQuery &Q) {
diff --git a/llvm/test/Analysis/ValueTracking/known-non-zero.ll b/llvm/test/Analysis/ValueTracking/known-non-zero.ll
index f64303f17301504..dbec47ea0ae261a 100644
--- a/llvm/test/Analysis/ValueTracking/known-non-zero.ll
+++ b/llvm/test/Analysis/ValueTracking/known-non-zero.ll
@@ -1163,11 +1163,7 @@ define i1 @sdiv_known_non_zero_fail(i8 %x, i8 %y) {
define <2 x i1> @cmp_excludes_zero_with_nonsplat_vec(<2 x i8> %a, <2 x i8> %b) {
; CHECK-LABEL: @cmp_excludes_zero_with_nonsplat_vec(
-; CHECK-NEXT: [[C:%.*]] = icmp sge <2 x i8> [[A:%.*]], <i8 1, i8 4>
-; CHECK-NEXT: [[S:%.*]] = select <2 x i1> [[C]], <2 x i8> [[A]], <2 x i8> <i8 4, i8 5>
-; CHECK-NEXT: [[AND:%.*]] = or <2 x i8> [[S]], [[B:%.*]]
-; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[AND]], zeroinitializer
-; CHECK-NEXT: ret <2 x i1> [[R]]
+; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%c = icmp sge <2 x i8> %a, <i8 1, i8 4>
%s = select <2 x i1> %c, <2 x i8> %a, <2 x i8> <i8 4, i8 5>
More information about the llvm-commits
mailing list