Skip to content

[WaveTransform] Widen back-edge i1 PHI operands instead of keeping them as lane masks#3371

Open
TejaX-Alaghari wants to merge 2 commits into
amd-feature/wave-transformfrom
amd/dev/tmahatej/wave-transform/fix-copyPhysReg-crash
Open

[WaveTransform] Widen back-edge i1 PHI operands instead of keeping them as lane masks#3371
TejaX-Alaghari wants to merge 2 commits into
amd-feature/wave-transformfrom
amd/dev/tmahatej/wave-transform/fix-copyPhysReg-crash

Conversation

@TejaX-Alaghari

@TejaX-Alaghari TejaX-Alaghari commented Jul 14, 2026

Copy link
Copy Markdown

Currently, a divergent i1 whose only use is the loop-header PHI it feeds through a self-back-edge was wrongly reclassified as a block-local lane mask by AMDGPUFinalizeISelWaveTransform (in canTreatAsLocalLaneMask()).

It makes that decision by checking whether the value feeding PHI "leaves" its block, but a PHI operand belongs to its predecessor edge, not the block the PHI sits in — so a self-back-edge use looks local when it isn't.

Because the PHI destination is always widened to vgpr_32, this produced a mixed-class vgpr_32 = PHI(vgpr_32, <lane mask>):

  • wave64: lowers to an illegal 32-bit-VGPR = COPY 64-bit-SGPR and asserts in SIInstrInfo::copyPhysReg during Post-RA pseudo expansion.
  • wave32: no assert, but silently broadcasts the packed lane-mask word to every lane instead of carrying the per-lane i1 (miscompile).

This PR aims to fix this behavior by treating any PHI use as leaving the block. Every vreg_1 PHI is unconditionally widened to vgpr_32, so a value feeding one can never stay a lane mask.

@TejaX-Alaghari TejaX-Alaghari requested a review from cdevadas July 14, 2026 14:53
@rocm-cciapp

rocm-cciapp Bot commented Jul 14, 2026

Copy link
Copy Markdown

@TejaX-Alaghari TejaX-Alaghari changed the title [WaveTransform] Fix wave64 copyPhysReg assert on divergent i1 loop back-edge [WaveTransform] Prevent back-edge i1 PHI operands widening to lane mask Jul 14, 2026
@rocm-cciapp

rocm-cciapp Bot commented Jul 14, 2026

Copy link
Copy Markdown

@TejaX-Alaghari TejaX-Alaghari changed the title [WaveTransform] Prevent back-edge i1 PHI operands widening to lane mask [WaveTransform] Prevent back-edge i1 PHI operands from becoming a lane mask Jul 14, 2026
@TejaX-Alaghari TejaX-Alaghari changed the title [WaveTransform] Prevent back-edge i1 PHI operands from becoming a lane mask [WaveTransform] Widen back-edge i1 PHI operands instead of keeping them as lane masks Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant