[llvm] [SCEV] Collect loop guards once in getSmallConstantTripMultiple (NFC). (PR #219722)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 30 09:21:58 PDT 2026
================
@@ -8411,23 +8411,29 @@ unsigned ScalarEvolution::getSmallConstantTripMultiple(const Loop *L) {
SmallVector<BasicBlock *, 8> ExitingBlocks;
L->getExitingBlocks(ExitingBlocks);
- std::optional<unsigned> Res;
- for (auto *ExitingBB : ExitingBlocks) {
- unsigned Multiple = getSmallConstantTripMultiple(L, ExitingBB);
- if (!Res)
- Res = Multiple;
- Res = std::gcd(*Res, Multiple);
- }
- return Res.value_or(1);
+ // An exit with an uncomputable exit count makes the result 1.
+ if (ExitingBlocks.empty() ||
+ any_of(ExitingBlocks, [this, L](BasicBlock *ExitingBB) {
+ return isa<SCEVCouldNotCompute>(getExitCount(L, ExitingBB));
+ }))
+ return 1;
+
+ LoopGuards Guards = LoopGuards::collect(L, *this);
+ unsigned Res = 0;
+ for (BasicBlock *ExitingBB : ExitingBlocks)
+ Res = std::gcd(
+ Res, getSmallConstantTripMultiple(getExitCount(L, ExitingBB), Guards));
+ return Res;
}
----------------
zhangweize9-cyber wrote:
I don't think this counts as a non-functional change. Because of the introduction of cyclic protection.
I understand that you added the `LoopGuards::collect()` function to perform boundary safety completion.
Since you changed the original logic, you need to add test cases.
https://github.com/llvm/llvm-project/pull/219722
More information about the llvm-commits
mailing list