[llvm] [Pipeliner] Fix Phi node dependency calculation (PR #160056)
    Santanu Das via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Tue Oct 21 05:47:45 PDT 2025
    
    
  
quic-santdas wrote:
> `mayOverlapInLaterIter()` should only return false when it is guaranteed that there are no dependencies. Otherwise, it may lead to incorrect scheduling. This change seems to allow the function to return false even when dependencies could exist.
The function mayOverlapInLaterIter() returns true if it finds that there 'may' be loop carried dependences between BaseMI and OtherMI. This patch fixes a corner case when it assumes a dependency which does not actually exist.
When the base registers are identical, we can say that they overlap. However, when they are not, it requires a deeper look. so, it checks for the definitions of the base registers by which they get to the Phi nodes.
>From the PHI nodes, it gets the InitVal and the LoopVal values. For these definitions, it takes the InitVals of both the operands.
- If both point to the same location, we do further alias analysis since there might be overlap (InitDefB->isIdenticalTo(*InitDefO) == true)
- If both point to different location, but one is a PHI that includes the other as an operand --> it requires further analysis (InitDefB->isIdenticalTo(*InitDefO) == false, doesOverlap(InitDefB, InitDefO) == true OR doesOverlap(InitDefO, InitDefB) == true)
- The initial values come from completely different sources → Likely no overlap → Return true to be conservative (InitDefB->isIdenticalTo(*InitDefO) == false, doesOverlap(InitDefB, InitDefO) == false,  doesOverlap(InitDefO, InitDefB) == false)
Example where this matters:
Outer Loop:
    %OuterPhi = PHI [%Input, Entry], [%Output, OuterBackedge]
Inner Loop:
    %BaseRegB = PHI [%OuterPhi, OuterLoop], [%InnerUpdate, InnerBackedge]
    %BaseRegO = PHI [%Output, OuterLoop], [%InnerUpdate2, InnerBackedge]
Here:
InitDefB = %OuterPhi (a PHI node)
InitDefO = %Output (some instruction)
Without the fix:
InitDefB->isIdenticalTo(*InitDefO) = false (different instructions)
Would return true (assume overlap), creating false dependency
With the fix:
doesOverlap(InitDefB, InitDefO) checks if %OuterPhi has %Output as an operand
If %OuterPhi = PHI [%Input, Entry], [%Output, OuterBackedge], then YES!
They overlap through the PHI → Continue analysis instead of bailing out.
https://github.com/llvm/llvm-project/pull/160056
    
    
More information about the llvm-commits
mailing list