[llvm] [ValueTracking] Add support for non-splat vecs in cmpExcludesZero (PR #68331)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 6 10:02:27 PDT 2023


================
@@ -569,11 +569,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 EleIdx = 0, NEle = VC->getNumElements(); EleIdx < NEle;
----------------
nikic wrote:

EleIdx -> ElemIdx or Idx

https://github.com/llvm/llvm-project/pull/68331


More information about the llvm-commits mailing list