Skip to content

Commit 86904ee

Browse files
committed
[HashRecognize] Tighten pre-conditions for analysis
Exit early if the TC is not a byte-multiple, as optimization works by dividing TC by 8. Also delay the SCEV TC query.
1 parent 40d2f39 commit 86904ee

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

llvm/lib/Analysis/HashRecognize.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,14 @@ std::variant<PolynomialInfo, ErrBits, StringRef>
561561
HashRecognize::recognizeCRC() const {
562562
if (!L.isInnermost())
563563
return "Loop is not innermost";
564-
unsigned TC = SE.getSmallConstantMaxTripCount(&L);
565-
if (!TC || TC > 256)
566-
return "Unable to find a small constant trip count";
567564
BasicBlock *Latch = L.getLoopLatch();
568565
BasicBlock *Exit = L.getExitBlock();
569566
const PHINode *IndVar = L.getCanonicalInductionVariable();
570-
if (!Latch || !Exit || !IndVar)
567+
if (!Latch || !Exit || !IndVar || L.getNumBlocks() != 1)
571568
return "Loop not in canonical form";
569+
unsigned TC = SE.getSmallConstantTripCount(&L);
570+
if (!TC || TC > 256 || TC % 8)
571+
return "Unable to find a small constant byte-multiple trip count";
572572

573573
auto R = getRecurrences(Latch, IndVar, L);
574574
if (!R)

llvm/test/Analysis/HashRecognize/cyclic-redundancy-check.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ exit: ; preds = %loop
384384
define i16 @not.crc.non.const.tc(i16 %crc.init, i32 %loop.limit) {
385385
; CHECK-LABEL: 'not.crc.non.const.tc'
386386
; CHECK-NEXT: Did not find a hash algorithm
387-
; CHECK-NEXT: Reason: Unable to find a small constant trip count
387+
; CHECK-NEXT: Reason: Unable to find a small constant byte-multiple trip count
388388
;
389389
entry:
390390
br label %loop
@@ -430,7 +430,7 @@ exit: ; preds = %loop
430430
define i16 @not.crc.tc.limit(i16 %crc.init) {
431431
; CHECK-LABEL: 'not.crc.tc.limit'
432432
; CHECK-NEXT: Did not find a hash algorithm
433-
; CHECK-NEXT: Reason: Unable to find a small constant trip count
433+
; CHECK-NEXT: Reason: Unable to find a small constant byte-multiple trip count
434434
;
435435
entry:
436436
br label %loop
@@ -617,7 +617,7 @@ loop: ; preds = %loop, %entry
617617
%crc.xor = xor i16 %crc.lshr, -24575
618618
%crc.next = select i1 %check.sb, i16 %crc.lshr, i16 %crc.xor
619619
%iv.next = add nuw nsw i8 %iv, 1
620-
%exit.cond = icmp samesign ult i8 %iv, 20
620+
%exit.cond = icmp samesign ult i8 %iv, 31
621621
br i1 %exit.cond, label %loop, label %exit
622622

623623
exit: ; preds = %loop

0 commit comments

Comments
 (0)