[llvm] [LoopFusion] Optimize away Phi nodes that are sunk from the 2nd loop preheader (PR #176503)
Ehsan Amiri via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 19 10:13:31 PST 2026
================
@@ -1453,7 +1453,19 @@ struct LoopFuser {
// insert instructions in reverse order to maintain dominance relationship
for (Instruction *I : reverse(SinkInsts)) {
assert(I->getParent() == FC1.Preheader);
- I->moveBefore(*FC1.ExitBlock, FC1.ExitBlock->getFirstInsertionPt());
+ if (isa<PHINode>(I)) {
+ // The Phis to be sunk should have only one incoming value, as is
+ // assured by the condition that the second loop is dominated by the
+ // first one which is enforced by isStrictlyAdjacent().
+ // Replace the phi uses with the corresponding incoming value to clean
+ // up the code.
+ assert(DT.dominates(FC0.ExitBlock, FC1.Preheader) &&
----------------
amehsan wrote:
I think Alireza is right about the assertion. The main point that we wanted to confirm here is something different though:
In the case of the guarded loops, the second loop is also guarded, and the preheader of the second loop has only one predecessor. So again any phi node must have one predecessor.
I believe the assertion should have two different conditions for the two cases.
https://github.com/llvm/llvm-project/pull/176503
More information about the llvm-commits
mailing list