[llvm] [SimpleLoopUnswitch] Allow trivial unswitch when exit LCSSA is a header PHI (PR #222962)
Ehsan Amiri via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 11 11:46:45 PDT 2026
================
@@ -275,6 +275,34 @@ static bool areLoopExitPHIsLoopInvariant(const Loop &L,
llvm_unreachable("Basic blocks should never be empty!");
}
+/// Return true if every LCSSA PHI in \p ExitBB has, on the edge from the
+/// \p ExitingBB, either a loop-invariant incoming value or a header PHI.
+///
+/// A header PHI is acceptable only when the caller has ensured \p ExitingBB
+/// dominates the latch: the invariant exit then fires on the first iteration,
+/// before the latch runs, so the header PHI still holds its preheader (entry)
+/// value.
+static bool areLoopExitPHIsTrivialFromHeader(const Loop &L,
----------------
amehsan wrote:
Will check more carefully the overall logic, but one comment for now
Can't you extend 'areLoopExitPHIsLoopInvariant' to check for the new condition too? We basically loop over all incoming values of the phi and expect it to be invariant or a header phi. Don't need two separate functions for those two checks. (The check for dominating the latch can be moved inside this extended function as well)
https://github.com/llvm/llvm-project/pull/222962
More information about the llvm-commits
mailing list