diff options
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 88 |
1 files changed, 47 insertions, 41 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index f8ec868..8bc0e7f2 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1091,15 +1091,15 @@ static void computeKnownBitsFromOperator(const Operator *I, break; } case Instruction::UDiv: { - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known2, Depth + 1, Q); Known = KnownBits::udiv(Known, Known2, Q.IIQ.isExact(cast<BinaryOperator>(I))); break; } case Instruction::SDiv: { - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known2, Depth + 1, Q); Known = KnownBits::sdiv(Known, Known2, Q.IIQ.isExact(cast<BinaryOperator>(I))); break; @@ -1107,7 +1107,7 @@ static void computeKnownBitsFromOperator(const Operator *I, case Instruction::Select: { auto ComputeForArm = [&](Value *Arm, bool Invert) { KnownBits Res(Known.getBitWidth()); - computeKnownBits(Arm, Res, Depth + 1, Q); + computeKnownBits(Arm, DemandedElts, Res, Depth + 1, Q); adjustKnownBitsForSelectArm(Res, I->getOperand(0), Arm, Invert, Depth, Q); return Res; }; @@ -1142,7 +1142,7 @@ static void computeKnownBitsFromOperator(const Operator *I, assert(SrcBitWidth && "SrcBitWidth can't be zero"); Known = Known.anyextOrTrunc(SrcBitWidth); - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); if (auto *Inst = dyn_cast<PossiblyNonNegInst>(I); Inst && Inst->hasNonNeg() && !Known.isNegative()) Known.makeNonNegative(); @@ -1164,7 +1164,8 @@ static void computeKnownBitsFromOperator(const Operator *I, if (match(I, m_ElementWiseBitCast(m_Value(V))) && V->getType()->isFPOrFPVectorTy()) { Type *FPType = V->getType()->getScalarType(); - KnownFPClass Result = computeKnownFPClass(V, fcAllFlags, Depth + 1, Q); + KnownFPClass Result = + computeKnownFPClass(V, DemandedElts, fcAllFlags, Depth + 1, Q); FPClassTest FPClasses = Result.KnownFPClasses; // TODO: Treat it as zero/poison if the use of I is unreachable. @@ -1245,7 +1246,7 @@ static void computeKnownBitsFromOperator(const Operator *I, unsigned SrcBitWidth = I->getOperand(0)->getType()->getScalarSizeInBits(); Known = Known.trunc(SrcBitWidth); - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); // If the sign bit of the input is known set or clear, then we know the // top bits of the result. Known = Known.sext(BitWidth); @@ -1305,14 +1306,14 @@ static void computeKnownBitsFromOperator(const Operator *I, break; } case Instruction::SRem: - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known2, Depth + 1, Q); Known = KnownBits::srem(Known, Known2); break; case Instruction::URem: - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known2, Depth + 1, Q); Known = KnownBits::urem(Known, Known2); break; case Instruction::Alloca: @@ -1465,17 +1466,17 @@ static void computeKnownBitsFromOperator(const Operator *I, unsigned OpNum = P->getOperand(0) == R ? 0 : 1; Instruction *RInst = P->getIncomingBlock(OpNum)->getTerminator(); - Instruction *LInst = P->getIncomingBlock(1-OpNum)->getTerminator(); + Instruction *LInst = P->getIncomingBlock(1 - OpNum)->getTerminator(); // Ok, we have a PHI of the form L op= R. Check for low // zero bits. RecQ.CxtI = RInst; - computeKnownBits(R, Known2, Depth + 1, RecQ); + computeKnownBits(R, DemandedElts, Known2, Depth + 1, RecQ); // We need to take the minimum number of known bits KnownBits Known3(BitWidth); RecQ.CxtI = LInst; - computeKnownBits(L, Known3, Depth + 1, RecQ); + computeKnownBits(L, DemandedElts, Known3, Depth + 1, RecQ); Known.Zero.setLowBits(std::min(Known2.countMinTrailingZeros(), Known3.countMinTrailingZeros())); @@ -1548,7 +1549,8 @@ static void computeKnownBitsFromOperator(const Operator *I, // want to waste time spinning around in loops. // TODO: See if we can base recursion limiter on number of incoming phi // edges so we don't overly clamp analysis. - computeKnownBits(IncValue, Known2, MaxAnalysisRecursionDepth - 1, RecQ); + computeKnownBits(IncValue, DemandedElts, Known2, + MaxAnalysisRecursionDepth - 1, RecQ); // See if we can further use a conditional branch into the phi // to help us determine the range of the value. @@ -1619,9 +1621,10 @@ static void computeKnownBitsFromOperator(const Operator *I, } if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) { switch (II->getIntrinsicID()) { - default: break; + default: + break; case Intrinsic::abs: { - computeKnownBits(I->getOperand(0), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known2, Depth + 1, Q); bool IntMinIsPoison = match(II->getArgOperand(1), m_One()); Known = Known2.abs(IntMinIsPoison); break; @@ -1637,7 +1640,7 @@ static void computeKnownBitsFromOperator(const Operator *I, Known.One |= Known2.One.byteSwap(); break; case Intrinsic::ctlz: { - computeKnownBits(I->getOperand(0), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known2, Depth + 1, Q); // If we have a known 1, its position is our upper bound. unsigned PossibleLZ = Known2.countMaxLeadingZeros(); // If this call is poison for 0 input, the result will be less than 2^n. @@ -1648,7 +1651,7 @@ static void computeKnownBitsFromOperator(const Operator *I, break; } case Intrinsic::cttz: { - computeKnownBits(I->getOperand(0), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known2, Depth + 1, Q); // If we have a known 1, its position is our upper bound. unsigned PossibleTZ = Known2.countMaxTrailingZeros(); // If this call is poison for 0 input, the result will be less than 2^n. @@ -1659,7 +1662,7 @@ static void computeKnownBitsFromOperator(const Operator *I, break; } case Intrinsic::ctpop: { - computeKnownBits(I->getOperand(0), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known2, Depth + 1, Q); // We can bound the space the count needs. Also, bits known to be zero // can't contribute to the population. unsigned BitsPossiblySet = Known2.countMaxPopulation(); @@ -1681,8 +1684,8 @@ static void computeKnownBitsFromOperator(const Operator *I, ShiftAmt = BitWidth - ShiftAmt; KnownBits Known3(BitWidth); - computeKnownBits(I->getOperand(0), Known2, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known3, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known3, Depth + 1, Q); Known.Zero = Known2.Zero.shl(ShiftAmt) | Known3.Zero.lshr(BitWidth - ShiftAmt); @@ -1691,27 +1694,30 @@ static void computeKnownBitsFromOperator(const Operator *I, break; } case Intrinsic::uadd_sat: - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known2, Depth + 1, Q); Known = KnownBits::uadd_sat(Known, Known2); break; case Intrinsic::usub_sat: - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known2, Depth + 1, Q); Known = KnownBits::usub_sat(Known, Known2); break; case Intrinsic::sadd_sat: - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known2, Depth + 1, Q); Known = KnownBits::sadd_sat(Known, Known2); break; case Intrinsic::ssub_sat: - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known2, Depth + 1, Q); Known = KnownBits::ssub_sat(Known, Known2); break; // Vec reverse preserves bits from input vec. case Intrinsic::vector_reverse: + computeKnownBits(I->getOperand(0), DemandedElts.reverseBits(), Known, + Depth + 1, Q); + break; // for min/max/and/or reduce, any bit common to each element in the // input vec is set in the output. case Intrinsic::vector_reduce_and: @@ -1738,31 +1744,31 @@ static void computeKnownBitsFromOperator(const Operator *I, break; } case Intrinsic::umin: - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known2, Depth + 1, Q); Known = KnownBits::umin(Known, Known2); break; case Intrinsic::umax: - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known2, Depth + 1, Q); Known = KnownBits::umax(Known, Known2); break; case Intrinsic::smin: - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known2, Depth + 1, Q); Known = KnownBits::smin(Known, Known2); break; case Intrinsic::smax: - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); - computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); + computeKnownBits(I->getOperand(1), DemandedElts, Known2, Depth + 1, Q); Known = KnownBits::smax(Known, Known2); break; case Intrinsic::ptrmask: { - computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); + computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth + 1, Q); const Value *Mask = I->getOperand(1); Known2 = KnownBits(Mask->getType()->getScalarSizeInBits()); - computeKnownBits(Mask, Known2, Depth + 1, Q); + computeKnownBits(Mask, DemandedElts, Known2, Depth + 1, Q); // TODO: 1-extend would be more precise. Known &= Known2.anyextOrTrunc(BitWidth); break; |