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

Piotr Fusik via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 15 05:02:59 PDT 2026


================
@@ -1582,6 +1590,164 @@ bool LoopIdiomRecognize::optimizeCRCLoop(const PolynomialInfo &Info) {
   if (TT.getArch() == Triple::hexagon)
     return false;
 
+  // In the clmul optimization, the first clmul uses 2*TC bits, and the second
+  // clmul uses CRCBW+TC bits. For simplicity, have both clmuls operate on the
+  // same bit width.
+  unsigned CRCBW = Info.LHS->getType()->getIntegerBitWidth();
+  unsigned ClmulBW = std::max(2 * Info.TripCount, CRCBW + Info.TripCount);
+  auto *ClmulTy = IntegerType::get(Info.LHS->getContext(), ClmulBW);
+
+  // The force-crc-clmul flag should cause the clmul optimization to run
+  // unconditionally.
+  if (ForceCRCClmul)
+    return optimizeCRCLoopUsingClmul(Info, ClmulTy) ||
+           (!ApplyCodeSizeHeuristics && optimizeCRCLoopUsingTableLookup(Info));
----------------
pfusik wrote:

It looks like `optimizeCRCLoopUsingClmul` always returns `true`, which makes this code dead.
Why not make it (and `optimizeCRCLoopUsingTableLookup`) `void` and simplify the logic here?

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


More information about the llvm-commits mailing list