[llvm] [LoopIdiom] Use costing to determine CRC strategy (PR #211040)
Sean Clarke via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 28 08:14:29 PDT 2026
================
@@ -1589,43 +1603,110 @@ bool LoopIdiomRecognize::optimizeCRCLoop(const PolynomialInfo &Info) {
if (TT.getArch() == Triple::hexagon)
return false;
- // The force-crc-clmul flag should cause the clmul optimization to run
- // unconditionally.
- if (ForceCRCClmul) {
+ // The Sarwate lookup table optimization requires a byte-multiple trip count,
+ // and should not be applied under any circumstances if optimizing for size.
+ bool TableStrategyPossible =
+ Info.TripCount % 8 == 0 && !ApplyCodeSizeHeuristics;
+
+ switch (CRCStrategy) {
+ default:
+ break;
+ case CRCStrategyKind::Table: {
+ if (TableStrategyPossible) {
+ optimizeCRCLoopUsingTableLookup(Info);
+ return true;
+ }
+ return false;
+ }
+ case CRCStrategyKind::Clmul:
optimizeCRCLoopUsingClmul(Info);
return true;
}
----------------
xarkenz wrote:
The `-loop-idiom-crc-strategy=table` case still needs to be "conditional" on `TC % 8 == 0` (since it would be applied incorrectly otherwise), but not `ApplyCodeSizeHeuristics`.
https://github.com/llvm/llvm-project/pull/211040
More information about the llvm-commits
mailing list