Skip to content

Commit 1a4cda3

Browse files
committed
[HashRecognize] NFC simplification
1 parent 3a96e7f commit 1a4cda3

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

llvm/lib/Analysis/HashRecognize.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,9 @@ class ValueEvolution {
102102

103103
public:
104104
// 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);
109108

110109
// Given a list of PHI nodes along with their incoming value from within the
111110
// loop, computeEvolutions computes the KnownBits of each of the PHI nodes on
@@ -116,19 +115,17 @@ class ValueEvolution {
116115
// precise error message.
117116
StringRef getError() const { return ErrStr; }
118117

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.
121120
SmallPtrSet<const Instruction *, 16> Visited;
122121

123122
// The computed KnownBits for each PHI node, which is populated after
124123
// computeEvolutions is called.
125124
KnownPhiMap KnownPhis;
126125
};
127126

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) {}
132129

133130
KnownBits ValueEvolution::computeBinOp(const BinaryOperator *I) {
134131
KnownBits KnownL(compute(I->getOperand(0)));
@@ -647,21 +644,22 @@ HashRecognize::recognizeCRC() const {
647644
if (SimpleRecurrence)
648645
PhiEvolutions.emplace_back(SimpleRecurrence.Phi, SimpleRecurrence.BO);
649646

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);
657648
if (!VE.computeEvolutions(PhiEvolutions))
658649
return VE.getError();
659650
KnownBits ResultBits = VE.KnownPhis.at(ConditionalRecurrence.Phi);
660651

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)
665663
return "Found stray unvisited instructions";
666664

667665
unsigned N = std::min(TC, ResultBits.getBitWidth());

0 commit comments

Comments
 (0)