[llvm] [LoopIdiomRecognize] Enable clmul optimization for CRC loops (PR #203405)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 12 23:21:38 PDT 2026
================
@@ -1665,24 +1649,105 @@ bool LoopIdiomRecognize::optimizeCRCLoop(const PolynomialInfo &Info) {
Indexer = Info.ByteOrderSwapped ? HiIdx(Builder, Indexer, "indexer.hi")
: LoByte(Builder, Indexer, "indexer.lo");
- // Always index into a GEP using the index type.
- Indexer = Builder.CreateZExt(
- Indexer, SE->getDataLayout().getIndexType(GV->getType()),
- "indexer.ext");
-
- // CRCTableLd = CRCTable[(iv'th byte of data) ^ (top|bottom) byte of CRC].
- Value *CRCTableGEP =
- Builder.CreateInBoundsGEP(CRCTy, GV, Indexer, "tbl.ptradd");
- Value *CRCTableLd = Builder.CreateLoad(CRCTy, CRCTableGEP, "tbl.ld");
-
- // CRCNext = (CRC (<<|>>) 8) ^ CRCTableLd, or simply CRCTableLd in case of
- // CRC-8.
- Value *CRCNext = CRCTableLd;
- if (CRCBW > 8) {
- Value *CRCShift = Info.ByteOrderSwapped
- ? Builder.CreateShl(CRC, 8, "crc.be.shift")
- : Builder.CreateLShr(CRC, 8, "crc.le.shift");
- CRCNext = Builder.CreateXor(CRCShift, CRCTableLd, "crc.next");
+ // Compute the next value of the CRC register based on Indexer. This could
+ // either be a table load or an on-the-fly computation, depending on whether
+ // llvm.clmul is fast on the target.
----------------
artagnon wrote:
> // Compute the next value of the CRC register based on Indexer. This could
> // either be a table load or an on-the-fly computation, depending on whether
> // llvm.clmul is fast on the target.
Not sure what Barrett reduction or clmul has to do with "on-the-fly computation".
https://github.com/llvm/llvm-project/pull/203405
More information about the llvm-commits
mailing list