[llvm] [LoopUnroll] Rotate loop before unrolling inside of UnrollRuntimeLoopRemainder (PR #148243)
Marek Sedláček via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 22 04:09:11 PDT 2025
================
@@ -32,12 +33,14 @@ class TargetTransformInfo;
/// header. If the loop header's size exceeds the threshold, the loop rotation
/// will give up. The flag IsUtilMode controls the heuristic used in the
/// LoopRotation. If it is true, the profitability heuristic will be ignored.
-LLVM_ABI bool LoopRotation(Loop *L, LoopInfo *LI,
- const TargetTransformInfo *TTI, AssumptionCache *AC,
- DominatorTree *DT, ScalarEvolution *SE,
- MemorySSAUpdater *MSSAU, const SimplifyQuery &SQ,
- bool RotationOnly, unsigned Threshold,
- bool IsUtilMode, bool PrepareForLTO = false);
+/// The ProfitabilityCheck function can override general profitability check.
+LLVM_ABI bool LoopRotation(
+ Loop *L, LoopInfo *LI, const TargetTransformInfo *TTI, AssumptionCache *AC,
+ DominatorTree *DT, ScalarEvolution *SE, MemorySSAUpdater *MSSAU,
+ const SimplifyQuery &SQ, bool RotationOnly, unsigned Threshold,
+ bool IsUtilMode, bool PrepareForLTO = false,
+ function_ref<bool(Loop *, ScalarEvolution *)> ProfitabilityCheck =
----------------
mark-sed wrote:
The idea was that the lambda could be useful later on in other parts which (will) use loopRotate to do a rotation under certain condition (similar to for example `replaceUsesWithIf`). In this exact case we have 1 loop and do the check before calling it so it is just a `return true` statement.
If you really prefer to have a flag instead, then I can change it. Nonetheless I still plan to make an NFC to refactor the loop rotate and split the legality and profitability checks, which will allow for loop unroll to ignore the existing profitability checks and not override it by this "filter" function.
https://github.com/llvm/llvm-project/pull/148243
More information about the llvm-commits
mailing list