@@ -247,16 +247,10 @@ KnownBits ValueEvolution::compute(const Value *V) {
247247}
248248
249249bool ValueEvolution::computeEvolutions (ArrayRef<PhiStepPair> PhiEvolutions) {
250- for (unsigned I = 0 ; I < TripCount; ++I) {
251- for (auto [Phi, Step] : PhiEvolutions) {
252- KnownBits KnownAtIter = computeInstr (Step);
253- if (KnownAtIter.getBitWidth () < I + 1 ) {
254- ErrStr = " Loop iterations exceed bitwidth of result" ;
255- return false ;
256- }
257- KnownPhis.emplace_or_assign (Phi, KnownAtIter);
258- }
259- }
250+ for (unsigned I = 0 ; I < TripCount; ++I)
251+ for (auto [Phi, Step] : PhiEvolutions)
252+ KnownPhis.emplace_or_assign (Phi, computeInstr (Step));
253+
260254 return ErrStr.empty ();
261255}
262256
@@ -583,6 +577,13 @@ HashRecognize::recognizeCRC() const {
583577 return " Recurrences not intertwined with XOR" ;
584578 }
585579
580+ // Make sure that the TC doesn't exceed the bitwidth of LHSAux, or LHS.
581+ Value *LHS = ConditionalRecurrence.Start ;
582+ Value *LHSAux = SimpleRecurrence ? SimpleRecurrence.Start : nullptr ;
583+ if (TC > (LHSAux ? LHSAux->getType ()->getIntegerBitWidth ()
584+ : LHS->getType ()->getIntegerBitWidth ()))
585+ return " Loop iterations exceed bitwidth of data" ;
586+
586587 // Make sure that the computed value is used in the exit block: this should be
587588 // true even if it is only really used in an outer loop's exit block, since
588589 // the loop is in LCSSA form.
@@ -612,12 +613,12 @@ HashRecognize::recognizeCRC() const {
612613 KnownBits ResultBits = VE.KnownPhis .at (ConditionalRecurrence.Phi );
613614
614615 auto IsZero = [](const KnownBits &K) { return K.isZero (); };
615- if (!checkExtractBits (ResultBits, TC, IsZero, *ByteOrderSwapped))
616+ if (!checkExtractBits (ResultBits, std::min (TC, ResultBits.getBitWidth ()),
617+ IsZero, *ByteOrderSwapped))
616618 return ErrBits (ResultBits, TC, *ByteOrderSwapped);
617619
618- Value *LHSAux = SimpleRecurrence ? SimpleRecurrence.Start : nullptr ;
619- return PolynomialInfo (TC, ConditionalRecurrence.Start , GenPoly, ComputedValue,
620- *ByteOrderSwapped, LHSAux);
620+ return PolynomialInfo (TC, LHS, GenPoly, ComputedValue, *ByteOrderSwapped,
621+ LHSAux);
621622}
622623
623624void CRCTable::print (raw_ostream &OS) const {
0 commit comments