[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:39 PDT 2026


================
@@ -376,6 +376,54 @@ CRCTable HashRecognize::genSarwateTable(const APInt &GenPoly,
   return Table;
 }
 
+// Divide one GF(2) polynomial by another.
+static APInt calculateGF2Quotient(APInt Dividend, const APInt &Divisor) {
+  unsigned DivisorDeg = Divisor.getActiveBits() - 1;
+  APInt Quotient = APInt::getZero(Dividend.getBitWidth());
+  unsigned DividendDeg;
+  while (!Dividend.isZero() &&
+         (DividendDeg = Dividend.getActiveBits() - 1) >= DivisorDeg) {
+    unsigned Shift = DividendDeg - DivisorDeg;
+    Quotient.setBit(Shift);
+    Dividend ^= Divisor.shl(Shift);
+  }
+  return Quotient;
+}
+
+// Generate constants (mu/reciprocal, P/generator) for a Barrett-style
+// reduction. This reduction allows the Sarwate table entry to be computed on
+// the fly, rather than requiring a load from memory (on supporting hardware).
----------------
artagnon wrote:

> This reduction allows the Sarwate table entry to be computed on
> the fly, rather than requiring a load from memory (on supporting hardware).

This is incorrect, and there seems to be a fundamental misunderstanding: Barrett-style reduction is merely an algorithm to approximate polynomial floor division with a polynomial multiplication (which can be done exactly on fixed-width integers). It does not compute Sarwate table entries.

https://github.com/llvm/llvm-project/pull/203405


More information about the llvm-commits mailing list