Commit 424b10d6 authored by Noah Goldstein's avatar Noah Goldstein
Browse files

[ValueTracking] Slight refactor to avoid unnecessary work; NFC

Two changes:
    1) Make some cases that conditionally returned unconditional.
    2) In cases of `Op0 != 0 || Op1 != 0` its better check `Op1` first
       as its more likely to be a constant due to canonicalization (so
       faster to get knownbits of).

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D149419
parent 5eedfff6
Loading
Loading
Loading
Loading
+7 −11
Original line number Diff line number Diff line
@@ -2796,8 +2796,8 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
                        I->getOperand(1));
  case Instruction::Or:
    // X | Y != 0 if X != 0 or Y != 0.
    return isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q) ||
           isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q);
    return isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q) ||
           isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q);
  case Instruction::SExt:
  case Instruction::ZExt:
    // ext X != 0 if X != 0.
@@ -2862,8 +2862,8 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
    // non-zero.
    auto *BO = cast<OverflowingBinaryOperator>(V);
    if (Q.IIQ.hasNoUnsignedWrap(BO))
      return isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q) ||
             isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q);
      return isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q) ||
             isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q);

    return isNonZeroAdd(DemandedElts, Depth, Q, BitWidth, I->getOperand(0),
                        I->getOperand(1), Q.IIQ.hasNoSignedWrap(BO));
@@ -2939,9 +2939,7 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
      case Intrinsic::bitreverse:
      case Intrinsic::bswap:
      case Intrinsic::ctpop:
        if (isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q))
          return true;
        break;
        return isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q);
      case Intrinsic::ssub_sat:
        return isNonZeroSub(DemandedElts, Depth, Q, BitWidth,
                            II->getArgOperand(0), II->getArgOperand(1));
@@ -2951,10 +2949,8 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
                            /*NSW*/ true);
      case Intrinsic::umax:
      case Intrinsic::uadd_sat:
        if (isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q) ||
            isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q))
          return true;
        break;
        return isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q) ||
               isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q);
      case Intrinsic::smin:
      case Intrinsic::smax: {
        auto KnownOpImpliesNonZero = [&](const KnownBits &K) {