@@ -102,10 +102,9 @@ class ValueEvolution {
102
102
103
103
public:
104
104
// ValueEvolution is meant to be constructed with the TripCount of the loop,
105
- // whether the polynomial algorithm is big-endian for the significant-bit
106
- // check, and an initial value for the Visited set.
107
- ValueEvolution (unsigned TripCount, bool ByteOrderSwapped,
108
- ArrayRef<const Instruction *> InitVisited);
105
+ // and a boolean indicating whether the polynomial algorithm is big-endian
106
+ // (for the significant-bit check).
107
+ ValueEvolution (unsigned TripCount, bool ByteOrderSwapped);
109
108
110
109
// Given a list of PHI nodes along with their incoming value from within the
111
110
// loop, computeEvolutions computes the KnownBits of each of the PHI nodes on
@@ -116,19 +115,17 @@ class ValueEvolution {
116
115
// precise error message.
117
116
StringRef getError () const { return ErrStr; }
118
117
119
- // A set of instructions visited by ValueEvolution. Anything that's not in the
120
- // use-def chain of the PHIs' evolution will not be visited .
118
+ // A set of Instructions visited by ValueEvolution. The only unvisited
119
+ // instructions will be ones not on the use-def chain of the PHIs' evolutions .
121
120
SmallPtrSet<const Instruction *, 16 > Visited;
122
121
123
122
// The computed KnownBits for each PHI node, which is populated after
124
123
// computeEvolutions is called.
125
124
KnownPhiMap KnownPhis;
126
125
};
127
126
128
- ValueEvolution::ValueEvolution (unsigned TripCount, bool ByteOrderSwapped,
129
- ArrayRef<const Instruction *> InitVisited)
130
- : TripCount(TripCount), ByteOrderSwapped(ByteOrderSwapped),
131
- Visited(InitVisited.begin(), InitVisited.end()) {}
127
+ ValueEvolution::ValueEvolution (unsigned TripCount, bool ByteOrderSwapped)
128
+ : TripCount(TripCount), ByteOrderSwapped(ByteOrderSwapped) {}
132
129
133
130
KnownBits ValueEvolution::computeBinOp (const BinaryOperator *I) {
134
131
KnownBits KnownL (compute (I->getOperand (0 )));
@@ -647,21 +644,22 @@ HashRecognize::recognizeCRC() const {
647
644
if (SimpleRecurrence)
648
645
PhiEvolutions.emplace_back (SimpleRecurrence.Phi , SimpleRecurrence.BO );
649
646
650
- // Initialize the Visited set in ValueEvolution with the IndVar-related
651
- // instructions.
652
- std::initializer_list<const Instruction *> InitVisited = {
653
- IndVar, Latch->getTerminator (), L.getLatchCmpInst (),
654
- cast<Instruction>(IndVar->getIncomingValueForBlock (Latch))};
655
-
656
- ValueEvolution VE (TC, *ByteOrderSwapped, InitVisited);
647
+ ValueEvolution VE (TC, *ByteOrderSwapped);
657
648
if (!VE.computeEvolutions (PhiEvolutions))
658
649
return VE.getError ();
659
650
KnownBits ResultBits = VE.KnownPhis .at (ConditionalRecurrence.Phi );
660
651
661
- // Any unvisited instructions from the KnownBits propagation can complicate
662
- // the optimization, which would just replace the entire loop with the
663
- // table-lookup version of the hash algorithm.
664
- if (std::distance (Latch->begin (), Latch->end ()) != VE.Visited .size ())
652
+ // There must be exactly four unvisited instructions, corresponding to the
653
+ // IndVar PHI:
654
+ // IndVar
655
+ // Latch->getTerminator()
656
+ // L.getLatchCmpInst(),
657
+ // IndVar->getIncomingValueForBlock(Latch))
658
+ //
659
+ // Any other unvisited instructions from the KnownBits propagation can
660
+ // complicate the optimization, which would just replace the entire loop with
661
+ // the table-lookup version of the hash algorithm.
662
+ if (std::distance (Latch->begin (), Latch->end ()) != VE.Visited .size () + 4 )
665
663
return " Found stray unvisited instructions" ;
666
664
667
665
unsigned N = std::min (TC, ResultBits.getBitWidth ());
0 commit comments