From: Max Kazantsev Date: Tue, 11 Oct 2022 11:01:58 +0000 (+0700) Subject: [NFC] Factor out collection of unswitch candidate to a separate function X-Git-Tag: upstream/17.0.6~30977 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=91aa9097ae52c39c0b077faf03ab58af0ee15d2d;p=platform%2Fupstream%2Fllvm.git [NFC] Factor out collection of unswitch candidate to a separate function Just to make the code more structured and easier to understand. --- diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp index edb9e3a..c24e8df 100644 --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -2733,17 +2733,13 @@ static int CalculateUnswitchCostMultiplier( return CostMultiplier; } -static bool unswitchBestCondition( - Loop &L, DominatorTree &DT, LoopInfo &LI, AssumptionCache &AC, - AAResults &AA, TargetTransformInfo &TTI, - function_ref)> UnswitchCB, - ScalarEvolution *SE, MemorySSAUpdater *MSSAU, - function_ref DestroyLoopCB) { - // Collect all invariant conditions within this loop (as opposed to an inner - // loop which would be handled when visiting that inner loop). - SmallVector>, 4> - UnswitchCandidates; - +static bool collectUnswitchCandidates( + SmallVectorImpl > > & + UnswitchCandidates, + IVConditionInfo &PartialIVInfo, Instruction *&PartialIVCondBranch, + const Loop &L, const LoopInfo &LI, AAResults &AA, + const MemorySSAUpdater *MSSAU) { + assert(UnswitchCandidates.empty() && "Should be!"); // Whether or not we should also collect guards in the loop. bool CollectGuards = false; if (UnswitchGuards) { @@ -2753,7 +2749,6 @@ static bool unswitchBestCondition( CollectGuards = true; } - IVConditionInfo PartialIVInfo; for (auto *BB : L.blocks()) { if (LI.getLoopFor(BB) != &L) continue; @@ -2802,7 +2797,6 @@ static bool unswitchBestCondition( } } - Instruction *PartialIVCondBranch = nullptr; if (MSSAU && !findOptionMDForLoop(&L, "llvm.loop.unswitch.partial.disable") && !any_of(UnswitchCandidates, [&L](auto &TerminatorAndInvariants) { return TerminatorAndInvariants.first == L.getHeader()->getTerminator(); @@ -2820,9 +2814,24 @@ static bool unswitchBestCondition( {L.getHeader()->getTerminator(), std::move(ValsToDuplicate)}); } } + return !UnswitchCandidates.empty(); +} +static bool unswitchBestCondition( + Loop &L, DominatorTree &DT, LoopInfo &LI, AssumptionCache &AC, + AAResults &AA, TargetTransformInfo &TTI, + function_ref)> UnswitchCB, + ScalarEvolution *SE, MemorySSAUpdater *MSSAU, + function_ref DestroyLoopCB) { + // Collect all invariant conditions within this loop (as opposed to an inner + // loop which would be handled when visiting that inner loop). + SmallVector >, 4> + UnswitchCandidates; + IVConditionInfo PartialIVInfo; + Instruction *PartialIVCondBranch = nullptr; // If we didn't find any candidates, we're done. - if (UnswitchCandidates.empty()) + if (!collectUnswitchCandidates(UnswitchCandidates, PartialIVInfo, + PartialIVCondBranch, L, LI, AA, MSSAU)) return false; // Check if there are irreducible CFG cycles in this loop. If so, we cannot