[llvm] [SimpleLoopUnswitch] Allow trivial unswitch when exit LCSSA is a header PHI (PR #222962)
Pablo Reble via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 16 14:56:06 PDT 2026
================
@@ -790,6 +807,18 @@ static bool unswitchTrivialBranch(Loop &L, CondBrInst &BI, DominatorTree &DT,
rewritePHINodesForExitAndUnswitchedBlocks(*LoopExitBB, *UnswitchedBB,
*ParentBB, *OldPH, FullUnswitch);
+ // OldPH branches here without entering the loop, so a header PHI is still
+ // its entry value. Read it from NewPH, the preheader created by the split.
+ if (TrivialFromHeader)
+ for (PHINode &PN : UnswitchedBB->phis())
+ for (unsigned I = 0, E = PN.getNumIncomingValues(); I != E; ++I) {
----------------
reble wrote:
NIT: Adding braces to the outer for loop for consistency. Also, you might want to consider renaming `I` to e.g. `Idx` here, since `I` is used for Instruction in the remainder of this file.
https://github.com/llvm/llvm-project/pull/222962
More information about the llvm-commits
mailing list