@@ -90,7 +90,6 @@ class ValueEvolution {
90
90
const bool ByteOrderSwapped;
91
91
APInt GenPoly;
92
92
StringRef ErrStr;
93
- KnownPhiMap KnownPhis;
94
93
95
94
KnownBits computeBinOp (const BinaryOperator *I);
96
95
KnownBits computeInstr (const Instruction *I);
@@ -107,8 +106,10 @@ class ValueEvolution {
107
106
// Given a list of PHI nodes along with their incoming value from within the
108
107
// loop, and the trip-count of the loop, computeEvolutions
109
108
// computes the KnownBits of each of the PHI nodes on the final iteration.
110
- std::optional<KnownPhiMap>
111
- computeEvolutions (ArrayRef<PhiStepPair> PhiEvolutions);
109
+ bool computeEvolutions (ArrayRef<PhiStepPair> PhiEvolutions);
110
+
111
+ // The resulting KnownBits for each PHI node.
112
+ KnownPhiMap KnownPhis;
112
113
};
113
114
114
115
ValueEvolution::ValueEvolution (unsigned TripCount, bool ByteOrderSwapped)
@@ -184,7 +185,8 @@ KnownBits ValueEvolution::computeInstr(const Instruction *I) {
184
185
// We need to check LCR against [0, 2) in the little-endian case, because
185
186
// the RCR check is insufficient: it is simply [0, 1).
186
187
if (!ByteOrderSwapped) {
187
- KnownBits KnownL = compute (L).zextOrTrunc (BitWidth);
188
+ KnownBits KnownL = compute (L);
189
+ BitWidth = KnownL.getBitWidth ();
188
190
auto LCR = ConstantRange::fromKnownBits (KnownL, false );
189
191
auto CheckLCR =
190
192
ConstantRange (APInt::getZero (BitWidth), APInt (BitWidth, 2 ));
@@ -195,13 +197,13 @@ KnownBits ValueEvolution::computeInstr(const Instruction *I) {
195
197
}
196
198
197
199
// Check that the predication is on (most|least) significant bit.
198
- KnownBits KnownR = compute (R).zextOrTrunc (BitWidth);
200
+ KnownBits KnownR = compute (R);
201
+ BitWidth = KnownR.getBitWidth ();
199
202
auto RCR = ConstantRange::fromKnownBits (KnownR, false );
200
203
auto AllowedR = ConstantRange::makeAllowedICmpRegion (Pred, RCR);
201
- ConstantRange LSBRange (APInt::getZero (BitWidth), APInt (BitWidth, 1 ));
202
- ConstantRange MSBRange (APInt::getZero (BitWidth),
203
- APInt::getSignedMinValue (BitWidth));
204
- const ConstantRange &CheckRCR = ByteOrderSwapped ? MSBRange : LSBRange;
204
+ ConstantRange CheckRCR (APInt::getZero (BitWidth),
205
+ ByteOrderSwapped ? APInt::getSignedMinValue (BitWidth)
206
+ : APInt (BitWidth, 1 ));
205
207
if (AllowedR == CheckRCR)
206
208
return compute (TV);
207
209
if (AllowedR.inverse () == CheckRCR)
@@ -242,19 +244,18 @@ KnownBits ValueEvolution::compute(const Value *V) {
242
244
243
245
// Takes every PHI-step pair in PhiEvolutions, and computes KnownBits on the
244
246
// final iteration, using KnownBits from the previous iteration.
245
- std::optional<KnownPhiMap>
246
- ValueEvolution::computeEvolutions (ArrayRef<PhiStepPair> PhiEvolutions) {
247
+ bool ValueEvolution::computeEvolutions (ArrayRef<PhiStepPair> PhiEvolutions) {
247
248
for (unsigned I = 0 ; I < TripCount; ++I) {
248
249
for (auto [Phi, Step] : PhiEvolutions) {
249
250
KnownBits KnownAtIter = computeInstr (Step);
250
251
if (KnownAtIter.getBitWidth () < I + 1 ) {
251
252
ErrStr = " Loop iterations exceed bitwidth of result" ;
252
- return std::nullopt ;
253
+ return false ;
253
254
}
254
255
KnownPhis.emplace_or_assign (Phi, KnownAtIter);
255
256
}
256
257
}
257
- return hasError () ? std::nullopt : std::make_optional (KnownPhis );
258
+ return ! hasError ();
258
259
}
259
260
260
261
// / A structure that can hold either a Simple Recurrence or a Conditional
@@ -605,12 +606,10 @@ HashRecognize::recognizeCRC() const {
605
606
PhiEvolutions.emplace_back (SimpleRecurrence.Phi , SimpleRecurrence.BO );
606
607
607
608
ValueEvolution VE (TC, *ByteOrderSwapped);
608
- std::optional<KnownPhiMap> KnownPhis = VE.computeEvolutions (PhiEvolutions);
609
-
610
- if (VE.hasError ())
609
+ if (!VE.computeEvolutions (PhiEvolutions))
611
610
return VE.getError ();
611
+ KnownBits ResultBits = VE.KnownPhis .at (ConditionalRecurrence.Phi );
612
612
613
- KnownBits ResultBits = KnownPhis->at (ConditionalRecurrence.Phi );
614
613
auto IsZero = [](const KnownBits &K) { return K.isZero (); };
615
614
if (!checkExtractBits (ResultBits, TC, IsZero, *ByteOrderSwapped))
616
615
return ErrBits (ResultBits, TC, *ByteOrderSwapped);
0 commit comments