[llvm] [LoopIdiomRecognize] Enable clmul optimization for CRC loops (PR #203405)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 26 18:16:38 PDT 2026


================
@@ -376,6 +376,74 @@ CRCTable HashRecognize::genSarwateTable(const APInt &GenPoly,
   return Table;
 }
 
+// Perform polynomial (GF(2)) floor division. This is based on the
+// floor_division(S, P) algorithm in
+// https://www.corsix.org/content/barrett-reduction-polynomials. Note that the
+// maximum degree of the returned polynomial is
+// max(0, deg(Dividend) - deg(Divisor)), but the bit width will be the same as
+// that of Dividend.
+static APInt floorDivideGF2(APInt Dividend, APInt Divisor) {
+  assert(!Divisor.isZero() && "Cannot divide by zero");
+
+  // Extend the divisor bit width to match the dividend.
+  Divisor = Divisor.zext(Dividend.getBitWidth());
+
+  // Note that getActiveBits(x) returns deg(x)+1, but the computation below
+  // still holds.
----------------
8051Enthusiast wrote:

`x` is a bit suboptimal as a placeholder here given that it's used as the indeterminate for the polynomials below.

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


More information about the llvm-commits mailing list