llvm.org GIT mirror llvm / d493444
[KnownBits] Add bit counting methods to KnownBits struct and use them where possible This patch adds min/max population count, leading/trailing zero/one bit counting methods. The min methods return answers based on bits that are known without considering unknown bits. The max methods give answers taking into account the largest count that unknown bits could give. Differential Revision: https://reviews.llvm.org/D32931 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302925 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 3 years ago
17 changed file(s) with 136 addition(s) and 89 deletion(s). Raw diff Collapse all Expand all
132132 KnownBits zextOrTrunc(unsigned BitWidth) {
133133 return KnownBits(Zero.zextOrTrunc(BitWidth), One.zextOrTrunc(BitWidth));
134134 }
135
136 /// Returns the minimum number of trailing zero bits.
137 unsigned countMinTrailingZeros() const {
138 return Zero.countTrailingOnes();
139 }
140
141 /// Returns the minimum number of trailing one bits.
142 unsigned countMinTrailingOnes() const {
143 return One.countTrailingOnes();
144 }
145
146 /// Returns the minimum number of leading zero bits.
147 unsigned countMinLeadingZeros() const {
148 return Zero.countLeadingOnes();
149 }
150
151 /// Returns the minimum number of leading one bits.
152 unsigned countMinLeadingOnes() const {
153 return One.countLeadingOnes();
154 }
155
156 /// Returns the number of times the sign bit is replicated into the other
157 /// bits.
158 unsigned countMinSignBits() const {
159 if (isNonNegative())
160 return countMinLeadingZeros();
161 if (isNegative())
162 return countMinLeadingOnes();
163 return 0;
164 }
165
166 /// Returns the maximum number of trailing zero bits possible.
167 unsigned countMaxTrailingZeros() const {
168 return One.countTrailingZeros();
169 }
170
171 /// Returns the maximum number of trailing one bits possible.
172 unsigned countMaxTrailingOnes() const {
173 return Zero.countTrailingZeros();
174 }
175
176 /// Returns the maximum number of leading zero bits possible.
177 unsigned countMaxLeadingZeros() const {
178 return One.countLeadingZeros();
179 }
180
181 /// Returns the maximum number of leading one bits possible.
182 unsigned countMaxLeadingOnes() const {
183 return Zero.countLeadingZeros();
184 }
185
186 /// Returns the number of bits known to be one.
187 unsigned countMinPopulation() const {
188 return One.countPopulation();
189 }
190
191 /// Returns the maximum number of bits that could be one.
192 unsigned countMaxPopulation() const {
193 return getBitWidth() - Zero.countPopulation();
194 }
135195 };
136196
137197 } // end namespace llvm
117117 // known to be one.
118118 ComputeKnownBits(BitWidth, I, nullptr);
119119 AB = APInt::getHighBitsSet(BitWidth,
120 std::min(BitWidth, Known.One.countLeadingZeros()+1));
120 std::min(BitWidth, Known.countMaxLeadingZeros()+1));
121121 }
122122 break;
123123 case Intrinsic::cttz:
127127 // known to be one.
128128 ComputeKnownBits(BitWidth, I, nullptr);
129129 AB = APInt::getLowBitsSet(BitWidth,
130 std::min(BitWidth, Known.One.countTrailingZeros()+1));
130 std::min(BitWidth, Known.countMaxTrailingZeros()+1));
131131 }
132132 break;
133133 }
13161316 // If all valid bits in the shift amount are known zero, the first operand is
13171317 // unchanged.
13181318 unsigned NumValidShiftBits = Log2_32_Ceil(BitWidth);
1319 if (Known.Zero.countTrailingOnes() >= NumValidShiftBits)
1319 if (Known.countMinTrailingZeros() >= NumValidShiftBits)
13201320 return Op0;
13211321
13221322 return nullptr;
46354635 KnownBits Known(BitWidth);
46364636 computeKnownBits(U->getValue(), Known, getDataLayout(), 0, &AC,
46374637 nullptr, &DT);
4638 return Known.Zero.countTrailingOnes();
4638 return Known.countMinTrailingZeros();
46394639 }
46404640
46414641 // SCEVUDivExpr
347347 // Also compute a conservative estimate for high known-0 bits.
348348 // More trickiness is possible, but this is sufficient for the
349349 // interesting case of alignment computation.
350 unsigned TrailZ = Known.Zero.countTrailingOnes() +
351 Known2.Zero.countTrailingOnes();
352 unsigned LeadZ = std::max(Known.Zero.countLeadingOnes() +
353 Known2.Zero.countLeadingOnes(),
350 unsigned TrailZ = Known.countMinTrailingZeros() +
351 Known2.countMinTrailingZeros();
352 unsigned LeadZ = std::max(Known.countMinLeadingZeros() +
353 Known2.countMinLeadingZeros(),
354354 BitWidth) - BitWidth;
355355
356356 TrailZ = std::min(TrailZ, BitWidth);
755755 computeKnownBits(A, RHSKnown, Depth+1, Query(Q, I));
756756
757757 // Whatever high bits in c are zero are known to be zero.
758 Known.Zero.setHighBits(RHSKnown.Zero.countLeadingOnes());
759 // assume(v <_u c)
758 Known.Zero.setHighBits(RHSKnown.countMinLeadingZeros());
759 // assume(v <_u c)
760760 } else if (match(Arg, m_ICmp(Pred, m_V, m_Value(A))) &&
761761 Pred == ICmpInst::ICMP_ULT &&
762762 isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
766766 // Whatever high bits in c are zero are known to be zero (if c is a power
767767 // of 2, then one more).
768768 if (isKnownToBeAPowerOfTwo(A, false, Depth + 1, Query(Q, I)))
769 Known.Zero.setHighBits(RHSKnown.Zero.countLeadingOnes()+1);
769 Known.Zero.setHighBits(RHSKnown.countMinLeadingZeros() + 1);
770770 else
771 Known.Zero.setHighBits(RHSKnown.Zero.countLeadingOnes());
771 Known.Zero.setHighBits(RHSKnown.countMinLeadingZeros());
772772 }
773773 }
774774
921921 m_Value(Y))))) {
922922 Known2.resetAll();
923923 computeKnownBits(Y, Known2, Depth + 1, Q);
924 if (Known2.One.countTrailingOnes() > 0)
924 if (Known2.countMinTrailingOnes() > 0)
925925 Known.Zero.setBit(0);
926926 }
927927 break;
958958 // treat a udiv as a logical right shift by the power of 2 known to
959959 // be less than the denominator.
960960 computeKnownBits(I->getOperand(0), Known2, Depth + 1, Q);
961 unsigned LeadZ = Known2.Zero.countLeadingOnes();
961 unsigned LeadZ = Known2.countMinLeadingZeros();
962962
963963 Known2.resetAll();
964964 computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q);
965 unsigned RHSUnknownLeadingOnes = Known2.One.countLeadingZeros();
966 if (RHSUnknownLeadingOnes != BitWidth)
967 LeadZ = std::min(BitWidth,
968 LeadZ + BitWidth - RHSUnknownLeadingOnes - 1);
965 unsigned RHSMaxLeadingZeros = Known2.countMaxLeadingZeros();
966 if (RHSMaxLeadingZeros != BitWidth)
967 LeadZ = std::min(BitWidth, LeadZ + BitWidth - RHSMaxLeadingZeros - 1);
969968
970969 Known.Zero.setHighBits(LeadZ);
971970 break;
988987 if (Known.isNegative() && Known2.isNegative())
989988 // We can derive a lower bound on the result by taking the max of the
990989 // leading one bits.
991 MaxHighOnes = std::max(Known.One.countLeadingOnes(),
992 Known2.One.countLeadingOnes());
990 MaxHighOnes =
991 std::max(Known.countMinLeadingOnes(), Known2.countMinLeadingOnes());
993992 // If either side is non-negative, the result is non-negative.
994993 else if (Known.isNonNegative() || Known2.isNonNegative())
995994 MaxHighZeros = 1;
998997 if (Known.isNonNegative() && Known2.isNonNegative())
999998 // We can derive an upper bound on the result by taking the max of the
1000999 // leading zero bits.
1001 MaxHighZeros = std::max(Known.Zero.countLeadingOnes(),
1002 Known2.Zero.countLeadingOnes());
1000 MaxHighZeros = std::max(Known.countMinLeadingZeros(),
1001 Known2.countMinLeadingZeros());
10031002 // If either side is negative, the result is negative.
10041003 else if (Known.isNegative() || Known2.isNegative())
10051004 MaxHighOnes = 1;
10071006 // We can derive a lower bound on the result by taking the max of the
10081007 // leading one bits.
10091008 MaxHighOnes =
1010 std::max(Known.One.countLeadingOnes(), Known2.One.countLeadingOnes());
1009 std::max(Known.countMinLeadingOnes(), Known2.countMinLeadingOnes());
10111010 } else if (SPF == SPF_UMIN) {
10121011 // We can derive an upper bound on the result by taking the max of the
10131012 // leading zero bits.
10141013 MaxHighZeros =
1015 std::max(Known.Zero.countLeadingOnes(), Known2.Zero.countLeadingOnes());
1014 std::max(Known.countMinLeadingZeros(), Known2.countMinLeadingZeros());
10161015 }
10171016
10181017 // Only known if known in both the LHS and RHS.
11901189 computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
11911190 computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q);
11921191
1193 unsigned Leaders = std::max(Known.Zero.countLeadingOnes(),
1194 Known2.Zero.countLeadingOnes());
1192 unsigned Leaders =
1193 std::max(Known.countMinLeadingZeros(), Known2.countMinLeadingZeros());
11951194 Known.resetAll();
11961195 Known.Zero.setHighBits(Leaders);
11971196 break;
12121211 // to determine if we can prove known low zero bits.
12131212 KnownBits LocalKnown(BitWidth);
12141213 computeKnownBits(I->getOperand(0), LocalKnown, Depth + 1, Q);
1215 unsigned TrailZ = LocalKnown.Zero.countTrailingOnes();
1214 unsigned TrailZ = LocalKnown.countMinTrailingZeros();
12161215
12171216 gep_type_iterator GTI = gep_type_begin(I);
12181217 for (unsigned i = 1, e = I->getNumOperands(); i != e; ++i, ++GTI) {
12461245 computeKnownBits(Index, LocalKnown, Depth + 1, Q);
12471246 TrailZ = std::min(TrailZ,
12481247 unsigned(countTrailingZeros(TypeSize) +
1249 LocalKnown.Zero.countTrailingOnes()));
1248 LocalKnown.countMinTrailingZeros()));
12501249 }
12511250 }
12521251
12911290 KnownBits Known3(Known);
12921291 computeKnownBits(L, Known3, Depth + 1, Q);
12931292
1294 Known.Zero.setLowBits(std::min(Known2.Zero.countTrailingOnes(),
1295 Known3.Zero.countTrailingOnes()));
1293 Known.Zero.setLowBits(std::min(Known2.countMinTrailingZeros(),
1294 Known3.countMinTrailingZeros()));
12961295
12971296 if (DontImproveNonNegativePhiBits)
12981297 break;
14171416 computeKnownBits(I->getOperand(0), Known2, Depth + 1, Q);
14181417 // We can bound the space the count needs. Also, bits known to be zero
14191418 // can't contribute to the population.
1420 unsigned BitsPossiblySet = BitWidth - Known2.Zero.countPopulation();
1419 unsigned BitsPossiblySet = Known2.countMaxPopulation();
14211420 unsigned LowBits = Log2_32(BitsPossiblySet)+1;
14221421 Known.Zero.setBitsFrom(LowBits);
14231422 // TODO: we could bound KnownOne using the lower bound on the number
18681867 if (ConstantInt *Shift = dyn_cast(Y)) {
18691868 auto ShiftVal = Shift->getLimitedValue(BitWidth - 1);
18701869 // Is there a known one in the portion not shifted out?
1871 if (Known.One.countLeadingZeros() < BitWidth - ShiftVal)
1870 if (Known.countMaxLeadingZeros() < BitWidth - ShiftVal)
18721871 return true;
18731872 // Are all the bits to be shifted out known zero?
1874 if (Known.Zero.countTrailingOnes() >= ShiftVal)
1873 if (Known.countMinTrailingZeros() >= ShiftVal)
18751874 return isKnownNonZero(X, Depth, Q);
18761875 }
18771876 }
22832282
22842283 // If we know that the sign bit is either zero or one, determine the number of
22852284 // identical bits in the top of the input value.
2286 if (Known.isNonNegative())
2287 return std::max(FirstAnswer, Known.Zero.countLeadingOnes());
2288
2289 if (Known.isNegative())
2290 return std::max(FirstAnswer, Known.One.countLeadingOnes());
2291
2292 // computeKnownBits gave us no extra information about the top bits.
2293 return FirstAnswer;
2285 return std::max(FirstAnswer, Known.countMinSignBits());
22942286 }
22952287
22962288 /// This function computes the integer multiple of Base that equals V.
34483440 computeKnownBits(RHS, RHSKnown, DL, /*Depth=*/0, AC, CxtI, DT);
34493441 // Note that underestimating the number of zero bits gives a more
34503442 // conservative answer.
3451 unsigned ZeroBits = LHSKnown.Zero.countLeadingOnes() +
3452 RHSKnown.Zero.countLeadingOnes();
3443 unsigned ZeroBits = LHSKnown.countMinLeadingZeros() +
3444 RHSKnown.countMinLeadingZeros();
34533445 // First handle the easy case: if we have enough zero bits there's
34543446 // definitely no overflow.
34553447 if (ZeroBits >= BitWidth)
22162216 // Also compute a conservative estimate for high known-0 bits.
22172217 // More trickiness is possible, but this is sufficient for the
22182218 // interesting case of alignment computation.
2219 unsigned TrailZ = Known.Zero.countTrailingOnes() +
2220 Known2.Zero.countTrailingOnes();
2221 unsigned LeadZ = std::max(Known.Zero.countLeadingOnes() +
2222 Known2.Zero.countLeadingOnes(),
2219 unsigned TrailZ = Known.countMinTrailingZeros() +
2220 Known2.countMinTrailingZeros();
2221 unsigned LeadZ = std::max(Known.countMinLeadingZeros() +
2222 Known2.countMinLeadingZeros(),
22232223 BitWidth) - BitWidth;
22242224
22252225 Known.resetAll();
22322232 // treat a udiv as a logical right shift by the power of 2 known to
22332233 // be less than the denominator.
22342234 computeKnownBits(Op.getOperand(0), Known2, DemandedElts, Depth + 1);
2235 unsigned LeadZ = Known2.Zero.countLeadingOnes();
2235 unsigned LeadZ = Known2.countMinLeadingZeros();
22362236
22372237 computeKnownBits(Op.getOperand(1), Known2, DemandedElts, Depth + 1);
2238 unsigned RHSUnknownLeadingOnes = Known2.One.countLeadingZeros();
2239 if (RHSUnknownLeadingOnes != BitWidth)
2240 LeadZ = std::min(BitWidth,
2241 LeadZ + BitWidth - RHSUnknownLeadingOnes - 1);
2238 unsigned RHSMaxLeadingZeros = Known2.countMaxLeadingZeros();
2239 if (RHSMaxLeadingZeros != BitWidth)
2240 LeadZ = std::min(BitWidth, LeadZ + BitWidth - RHSMaxLeadingZeros - 1);
22422241
22432242 Known.Zero.setHighBits(LeadZ);
22442243 break;
23582357 case ISD::CTTZ_ZERO_UNDEF: {
23592358 computeKnownBits(Op.getOperand(0), Known2, DemandedElts, Depth + 1);
23602359 // If we have a known 1, its position is our upper bound.
2361 unsigned PossibleTZ = Known2.One.countTrailingZeros();
2360 unsigned PossibleTZ = Known2.countMaxTrailingZeros();
23622361 unsigned LowBits = Log2_32(PossibleTZ) + 1;
23632362 Known.Zero.setBitsFrom(LowBits);
23642363 break;
23672366 case ISD::CTLZ_ZERO_UNDEF: {
23682367 computeKnownBits(Op.getOperand(0), Known2, DemandedElts, Depth + 1);
23692368 // If we have a known 1, its position is our upper bound.
2370 unsigned PossibleLZ = Known2.One.countLeadingZeros();
2369 unsigned PossibleLZ = Known2.countMaxLeadingZeros();
23712370 unsigned LowBits = Log2_32(PossibleLZ) + 1;
23722371 Known.Zero.setBitsFrom(LowBits);
23732372 break;
23752374 case ISD::CTPOP: {
23762375 computeKnownBits(Op.getOperand(0), Known2, DemandedElts, Depth + 1);
23772376 // If we know some of the bits are zero, they can't be one.
2378 unsigned PossibleOnes = BitWidth - Known2.Zero.countPopulation();
2377 unsigned PossibleOnes = Known2.countMaxPopulation();
23792378 Known.Zero.setBitsFrom(Log2_32(PossibleOnes) + 1);
23802379 break;
23812380 }
24922491 // going to be 0 in the result. Both addition and complement operations
24932492 // preserve the low zero bits.
24942493 computeKnownBits(Op.getOperand(0), Known2, DemandedElts, Depth + 1);
2495 unsigned KnownZeroLow = Known2.Zero.countTrailingOnes();
2494 unsigned KnownZeroLow = Known2.countMinTrailingZeros();
24962495 if (KnownZeroLow == 0)
24972496 break;
24982497
24992498 computeKnownBits(Op.getOperand(1), Known2, DemandedElts, Depth + 1);
2500 KnownZeroLow = std::min(KnownZeroLow,
2501 Known2.Zero.countTrailingOnes());
2499 KnownZeroLow = std::min(KnownZeroLow, Known2.countMinTrailingZeros());
25022500 Known.Zero.setLowBits(KnownZeroLow);
25032501 break;
25042502 }
25252523 // and the other has the top 8 bits clear, we know the top 7 bits of the
25262524 // output must be clear.
25272525 computeKnownBits(Op.getOperand(0), Known2, DemandedElts, Depth + 1);
2528 unsigned KnownZeroHigh = Known2.Zero.countLeadingOnes();
2529 unsigned KnownZeroLow = Known2.Zero.countTrailingOnes();
2526 unsigned KnownZeroHigh = Known2.countMinLeadingZeros();
2527 unsigned KnownZeroLow = Known2.countMinTrailingZeros();
25302528
25312529 computeKnownBits(Op.getOperand(1), Known2, DemandedElts,
25322530 Depth + 1);
2533 KnownZeroHigh = std::min(KnownZeroHigh,
2534 Known2.Zero.countLeadingOnes());
2535 KnownZeroLow = std::min(KnownZeroLow,
2536 Known2.Zero.countTrailingOnes());
2531 KnownZeroHigh = std::min(KnownZeroHigh, Known2.countMinLeadingZeros());
2532 KnownZeroLow = std::min(KnownZeroLow, Known2.countMinTrailingZeros());
25372533
25382534 if (Opcode == ISD::ADDE || Opcode == ISD::ADDCARRY) {
25392535 // With ADDE and ADDCARRY, a carry bit may be added in, so we can only
25932589 computeKnownBits(Op.getOperand(0), Known, DemandedElts, Depth + 1);
25942590 computeKnownBits(Op.getOperand(1), Known2, DemandedElts, Depth + 1);
25952591
2596 uint32_t Leaders = std::max(Known.Zero.countLeadingOnes(),
2597 Known2.Zero.countLeadingOnes());
2592 uint32_t Leaders =
2593 std::max(Known.countMinLeadingZeros(), Known2.countMinLeadingZeros());
25982594 Known.resetAll();
25992595 Known.Zero.setHighBits(Leaders);
26002596 break;
27102706
27112707 // UMIN - we know that the result will have the maximum of the
27122708 // known zero leading bits of the inputs.
2713 unsigned LeadZero = Known.Zero.countLeadingOnes();
2714 LeadZero = std::max(LeadZero, Known2.Zero.countLeadingOnes());
2709 unsigned LeadZero = Known.countMinLeadingZeros();
2710 LeadZero = std::max(LeadZero, Known2.countMinLeadingZeros());
27152711
27162712 Known.Zero &= Known2.Zero;
27172713 Known.One &= Known2.One;
27252721
27262722 // UMAX - we know that the result will have the maximum of the
27272723 // known one leading bits of the inputs.
2728 unsigned LeadOne = Known.One.countLeadingOnes();
2729 LeadOne = std::max(LeadOne, Known2.One.countLeadingOnes());
2724 unsigned LeadOne = Known.countMinLeadingOnes();
2725 LeadOne = std::max(LeadOne, Known2.countMinLeadingOnes());
27302726
27312727 Known.Zero &= Known2.Zero;
27322728 Known.One &= Known2.One;
28422838 // Fall back to computeKnownBits to catch other known cases.
28432839 KnownBits Known;
28442840 computeKnownBits(Val, Known);
2845 return (Known.Zero.countPopulation() == BitWidth - 1) &&
2846 (Known.One.countPopulation() == 1);
2841 return (Known.countMaxPopulation() == 1) && (Known.countMinPopulation() == 1);
28472842 }
28482843
28492844 unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, unsigned Depth) const {
75197514 KnownBits Known(PtrWidth);
75207515 llvm::computeKnownBits(const_cast(GV), Known,
75217516 getDataLayout());
7522 unsigned AlignBits = Known.Zero.countTrailingOnes();
7517 unsigned AlignBits = Known.countMinTrailingZeros();
75237518 unsigned Align = AlignBits ? 1 << std::min(31U, AlignBits) : 0;
75247519 if (Align)
75257520 return MinAlign(Align, GVOffset);
660660
661661 unsigned RegSize = RegisterVT.getSizeInBits();
662662 unsigned NumSignBits = LOI->NumSignBits;
663 unsigned NumZeroBits = LOI->Known.Zero.countLeadingOnes();
663 unsigned NumZeroBits = LOI->Known.countMinLeadingZeros();
664664
665665 if (NumZeroBits == RegSize) {
666666 // The current value is a zero.
23042304 EVT VT = Op.getValueType();
23052305 DAG.computeKnownBits(Op, Known);
23062306
2307 return (VT.getSizeInBits() - Known.Zero.countLeadingOnes()) <= 24;
2307 return (VT.getSizeInBits() - Known.countMinLeadingZeros()) <= 24;
23082308 }
23092309
23102310 static bool isI24(SDValue Op, SelectionDAG &DAG) {
12081208
12091209 KnownBits Known(T->getBitWidth());
12101210 computeKnownBits(V, Known, DL);
1211 return Known.Zero.countLeadingOnes() >= IterCount;
1211 return Known.countMinLeadingZeros() >= IterCount;
12121212 }
12131213
12141214
1675116751 if (BitWidth > AndBitWidth) {
1675216752 KnownBits Known;
1675316753 DAG.computeKnownBits(Op0, Known);
16754 if (Known.Zero.countLeadingOnes() < BitWidth - AndBitWidth)
16754 if (Known.countMinLeadingZeros() < BitWidth - AndBitWidth)
1675516755 return SDValue();
1675616756 }
1675716757 LHS = Op1;
408408 {
409409 KnownBits Known;
410410 DAG.computeKnownBits(Value, Known);
411 return Known.Zero.countTrailingOnes() >= 2;
411 return Known.countMinTrailingZeros() >= 2;
412412 }
413413
414414 SDValue XCoreTargetLowering::
13831383
13841384 // Create a mask for bits above (ctlz) or below (cttz) the first known one.
13851385 bool IsTZ = II.getIntrinsicID() == Intrinsic::cttz;
1386 unsigned PossibleZeros = IsTZ ? Known.One.countTrailingZeros()
1387 : Known.One.countLeadingZeros();
1388 unsigned DefiniteZeros = IsTZ ? Known.Zero.countTrailingOnes()
1389 : Known.Zero.countLeadingOnes();
1386 unsigned PossibleZeros = IsTZ ? Known.countMaxTrailingZeros()
1387 : Known.countMaxLeadingZeros();
1388 unsigned DefiniteZeros = IsTZ ? Known.countMinTrailingZeros()
1389 : Known.countMinLeadingZeros();
13901390
13911391 // If all bits above (ctlz) or below (cttz) the first known one are known
13921392 // zero, this value is constant.
610610 SimplifyDemandedBits(I, 1, AllOnes, Known2, Depth + 1))
611611 return I;
612612
613 unsigned Leaders = Known2.Zero.countLeadingOnes();
613 unsigned Leaders = Known2.countMinLeadingZeros();
614614 Known.Zero = APInt::getHighBitsSet(BitWidth, Leaders) & DemandedMask;
615615 break;
616616 }
22632263 unsigned BitWidth = cast(Cond->getType())->getBitWidth();
22642264 KnownBits Known(BitWidth);
22652265 computeKnownBits(Cond, Known, 0, &SI);
2266 unsigned LeadingKnownZeros = Known.Zero.countLeadingOnes();
2267 unsigned LeadingKnownOnes = Known.One.countLeadingOnes();
2266 unsigned LeadingKnownZeros = Known.countMinLeadingZeros();
2267 unsigned LeadingKnownOnes = Known.countMinLeadingOnes();
22682268
22692269 // Compute the number of leading bits we can ignore.
22702270 // TODO: A better way to determine this would use ComputeNumSignBits().
260260
261261 computeKnownBits(V, Known, DL);
262262
263 if (Known.Zero.countLeadingOnes() >= HiBits)
263 if (Known.countMinLeadingZeros() >= HiBits)
264264 return VALRNG_KNOWN_SHORT;
265265
266 if (Known.One.countLeadingZeros() < HiBits)
266 if (Known.countMaxLeadingZeros() < HiBits)
267267 return VALRNG_LIKELY_LONG;
268268
269269 // Long integer divisions are often used in hashtable implementations. It's
10401040
10411041 KnownBits Known(BitWidth);
10421042 computeKnownBits(V, Known, DL, 0, AC, CxtI, DT);
1043 unsigned TrailZ = Known.Zero.countTrailingOnes();
1043 unsigned TrailZ = Known.countMinTrailingZeros();
10441044
10451045 // Avoid trouble with ridiculously large TrailZ values, such as
10461046 // those computed from a null pointer.
345345 if (!Safe) {
346346 KnownBits Known(BitWidth);
347347 computeKnownBits(OpA, Known, DL, 0, nullptr, OpA, &DT);
348 if (Known.Zero.countTrailingZeros() < (BitWidth - 1))
348 if (Known.countMaxTrailingOnes() < (BitWidth - 1))
349349 Safe = true;
350350 }
351351