[PATCH] D147900: [ValueTracking] Use `select` condition to help determine if `select` is non-zero

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 22 13:06:51 PDT 2023


nikic added inline comments.


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2939
       return true;
     break;
+  }
----------------
I have a hard time following the logic here at the end. What I expected to see was something like this:
```
    auto SelectArmIsNonZero = [&](bool IsTrueArm) {
      Value *Op = IsTrueArm ? I->getOperand(1) : I->getOperand(2);
      if (isKnownNonZero(Op, DemandedElts, Depth, Q))
        return true;

      // The condition of the select dominates the true/false arm. Check if the
      // condition implies that a given arm is non-zero.
      Value *X;
      CmpInst::Predicate Pred;
      if (!match(I->getOperand(0), m_c_ICmp(Pred, m_Specific(Op), m_Value(X))))
        return false;

      if (!IsTrueArm)
        Pred = ICmpInst::getInversePredicate(Pred);

      return cmpExcludesZero(Pred, X);
    };

    if (SelectArmIsNonZero(/* IsTrueArm */ true) &&
        SelectArmIsNonZero(/* IsTrueArm */ false))
      return true;
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147900/new/

https://reviews.llvm.org/D147900



More information about the llvm-commits mailing list