[llvm] [ValueTracking] Add support for non-splat vecs in cmpExcludesZero (PR #68331)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 5 19:14:45 PDT 2023
================
@@ -573,11 +573,31 @@ 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());
+ if (FVTy == nullptr)
+ return false;
+ Constant *VC = nullptr;
+ if (!match(RHS, m_ImmConstant(VC)))
+ return false;
+ for (unsigned EleIdx = 0, NEle = FVTy->getNumElements(); EleIdx < NEle;
+ ++EleIdx) {
+ Constant *EleC = VC->getAggregateElement(EleIdx);
+ if (EleC == nullptr)
+ return false;
+ ConstantInt *EleCI = dyn_cast<ConstantInt>(EleC);
+ if (EleCI == nullptr)
+ return false;
+ ConstantRange TrueValues =
+ ConstantRange::makeExactICmpRegion(Pred, EleCI->getValue());
+ if (TrueValues.contains(APInt::getZero(EleCI->getBitWidth())))
+ return false;
+ }
+ return true;
----------------
goldsteinn wrote:
Doesn't work for `ConstantDataSequential` (which is what the non-undef/poison ones tests are).
https://github.com/llvm/llvm-project/pull/68331
More information about the llvm-commits
mailing list