[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 01:56:37 PDT 2023


================
@@ -569,11 +569,30 @@ 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)))
-    return false;
+  if (match(RHS, m_APInt(C))) {
+    ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(Pred, *C);
+    return !TrueValues.contains(APInt::getZero(C->getBitWidth()));
+  }
 
-  ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(Pred, *C);
-  return !TrueValues.contains(APInt::getZero(C->getBitWidth()));
+  auto *FVTy = dyn_cast<FixedVectorType>(RHS->getType());
----------------
nikic wrote:

I think it would be better to cast RHS to ConstantDataVector here and then use getElementAsAPInt() on it. No point in round-tripping through ConstantInt just to extract the APInt again.

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


More information about the llvm-commits mailing list