Skip to content

Commit 130274f

Browse files
committed
[HashRecognize] Fix some minor things
1 parent bf5351e commit 130274f

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

llvm/lib/Analysis/HashRecognize.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
#include "llvm/Support/KnownBits.h"
7070

7171
using namespace llvm;
72+
using namespace PatternMatch;
73+
using namespace SCEVPatternMatch;
7274

7375
#define DEBUG_TYPE "hash-recognize"
7476

@@ -173,14 +175,12 @@ KnownBits ValueEvolution::computeBinOp(const BinaryOperator *I,
173175
/// Compute the KnownBits of Instruction \p I.
174176
KnownBits ValueEvolution::computeInstr(const Instruction *I,
175177
const KnownPhiMap &KnownPhis) {
176-
using namespace llvm::PatternMatch;
177-
178178
unsigned BitWidth = I->getType()->getScalarSizeInBits();
179179

180180
// We look up in the map that contains the KnownBits of the PHI from the
181181
// previous iteration.
182182
if (const PHINode *P = dyn_cast<PHINode>(I))
183-
return KnownPhis.lookup_or(P, {BitWidth});
183+
return KnownPhis.lookup_or(P, BitWidth);
184184

185185
// Compute the KnownBits for a Select(Cmp()), forcing it to take the take the
186186
// branch that is predicated on the (least|most)-significant-bit check.
@@ -196,7 +196,7 @@ KnownBits ValueEvolution::computeInstr(const Instruction *I,
196196
auto RCR = ConstantRange::fromKnownBits(KnownR, false);
197197

198198
// We need to check LCR against [0, 2) in the little-endian case, because
199-
// the RCR check is too lax: it is simply [0, SMIN).
199+
// the RCR check is insufficient: it is simply [0, 1).
200200
auto CheckLCR = ConstantRange(APInt::getZero(BitWidth), APInt(BitWidth, 2));
201201
if (!ByteOrderSwapped && LCR != CheckLCR) {
202202
ErrStr = "Bad LHS of significant-bit-check";
@@ -239,8 +239,6 @@ KnownBits ValueEvolution::computeInstr(const Instruction *I,
239239
/// Compute the KnownBits of Value \p V.
240240
KnownBits ValueEvolution::compute(const Value *V,
241241
const KnownPhiMap &KnownPhis) {
242-
using namespace llvm::PatternMatch;
243-
244242
unsigned BitWidth = V->getType()->getScalarSizeInBits();
245243

246244
const APInt *C;
@@ -262,7 +260,6 @@ ValueEvolution::computeEvolutions(ArrayRef<PhiStepPair> PhiEvolutions) {
262260
for (unsigned I = 0; I < TripCount; ++I) {
263261
AtIteration = I;
264262
for (auto [Phi, Step] : PhiEvolutions) {
265-
// Check that the {top, bottom} I bits are zero, with the rest unknown.
266263
KnownBits KnownAtIter = computeInstr(Step, KnownPhis);
267264
if (KnownAtIter.getBitWidth() < I + 1) {
268265
ErrStr = "Loop iterations exceed bitwidth of result";
@@ -271,8 +268,6 @@ ValueEvolution::computeEvolutions(ArrayRef<PhiStepPair> PhiEvolutions) {
271268
KnownPhis.emplace_or_assign(Phi, KnownAtIter);
272269
}
273270
}
274-
275-
// Return the final ComputedBits.
276271
return KnownPhis;
277272
}
278273

@@ -282,8 +277,6 @@ static BinaryOperator *
282277
digRecurrence(Instruction *V, const PHINode *P, const Loop &L,
283278
const APInt *&ExtraConst,
284279
Instruction::BinaryOps BOWithConstOpToMatch) {
285-
using namespace llvm::PatternMatch;
286-
287280
SmallVector<Instruction *> Worklist;
288281
Worklist.push_back(V);
289282
while (!Worklist.empty()) {
@@ -337,8 +330,6 @@ static bool matchConditionalRecurrence(
337330
return false;
338331

339332
for (unsigned Idx = 0; Idx != 2; ++Idx) {
340-
using namespace llvm::PatternMatch;
341-
342333
Value *FoundStep = P->getIncomingValue(Idx);
343334
Value *FoundStart = P->getIncomingValue(!Idx);
344335

@@ -374,7 +365,7 @@ static bool matchConditionalRecurrence(
374365

375366
/// A structure that can hold either a Simple Recurrence or a Conditional
376367
/// Recurrence. Note that in the case of a Simple Recurrence, Step is an operand
377-
/// of the BO, while in a Conditional Recurrence, Step is a SelectInst.
368+
/// of the BO, while in a Conditional Recurrence, it is a SelectInst.
378369
struct RecurrenceInfo {
379370
PHINode *Phi;
380371
BinaryOperator *BO;
@@ -452,7 +443,7 @@ static bool checkExtractBits(const KnownBits &Known, unsigned N,
452443
unsigned BitPos = ByteOrderSwapped ? 0 : Known.getBitWidth() - N;
453444
unsigned SwappedBitPos = ByteOrderSwapped ? N : 0;
454445

455-
// If there are no other bits, check that the entire thing is a constant.
446+
// Check that the entire thing is a constant.
456447
if (N == Known.getBitWidth())
457448
return CheckFn(Known.extractBits(N, 0));
458449

@@ -510,9 +501,9 @@ static bool arePHIsIntertwined(
510501

511502
// BOToMatch is usually XOR for CRC.
512503
if (BOToMatch != Instruction::BinaryOpsEnd) {
513-
if (none_of(Worklist, [BOToMatch](const Instruction *I) {
504+
if (count_if(Worklist, [BOToMatch](const Instruction *I) {
514505
return I->getOpcode() == BOToMatch;
515-
}))
506+
}) != 1)
516507
return false;
517508
}
518509

@@ -539,8 +530,6 @@ static bool arePHIsIntertwined(
539530
// equivalently shl/lshr. Return false when it is a UDiv, true when it is a Mul,
540531
// and std::nullopt otherwise.
541532
static std::optional<bool> isBigEndianBitShift(const SCEV *E) {
542-
using namespace llvm::SCEVPatternMatch;
543-
544533
if (match(E, m_scev_UDiv(m_SCEV(), m_scev_SpecificInt(2))))
545534
return false;
546535
if (match(E, m_scev_Mul(m_scev_SpecificInt(2), m_SCEV())))

0 commit comments

Comments
 (0)