This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU: Fix an assertion in SIOptimizeVGPRLiveRange
ClosedPublic

Authored by nhaehnle on Apr 25 2023, 8:06 AM.

Details

Summary

As the comment notes, the shader results in an INSERT_SUBREG with
"undef" (dead) operand in the Endif block. The register is considered
dead from a liveness analysis perspective. The correct thing to do seems
to be nothing: we keep the undef use of the register, the register
allocator should still be able to take the liveness into account
correctly.

Diff Detail

Unit TestsFailed

Event Timeline

nhaehnle created this revision.Apr 25 2023, 8:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 8:06 AM
nhaehnle requested review of this revision.Apr 25 2023, 8:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 8:06 AM
Herald added a subscriber: wdng. · View Herald Transcript

Could really use a mir test for these sorts of issues

llvm/lib/Target/AMDGPU/SIOptimizeVGPRLiveRange.cpp
535

Could this see an undef subregister def? Should probably be assert !O.readsReg() (or maybe the loop is buggy to begin with by using use_operands?)

llvm/test/CodeGen/AMDGPU/bug-deadlanes.ll
9–11

Can drop this

Why I cannot reproduce the assertion? I have tried on latest version and a version several days before.

llvm/lib/Target/AMDGPU/SIOptimizeVGPRLiveRange.cpp
535

Could this see an undef subregister def?

I guess not in SSA? or could you help point out what it would look like?

I think the undef use might also appear in blocks after Endif, so the assertion on part of the cases may be not quite helpful. As we already checked the register is not live in Endif, maybe we can just replace under the check if (UseMI->isPHI() && UseBlock == Endif). But leaving some comment here still useful.

nhaehnle marked an inline comment as done.Apr 26 2023, 6:28 AM

It turns out my LLVM version was a bit old. In current main it needs -amdgpu-codegenprepare-break-large-phis=false to reproduce. And I'm adding a severely reduced MIR test.

llvm/lib/Target/AMDGPU/SIOptimizeVGPRLiveRange.cpp
535

!O.readsReg() seems to make sense, yes.

I found the loop a bit surprising as well, but I'm pretty sure it makes sense due to the way it checks for specific basic blocks (that have previously been collected taking liveness into account).

nhaehnle updated this revision to Diff 517145.Apr 26 2023, 6:28 AM

Add MIR test, change to !O.readsReg()

ruiling accepted this revision.Apr 26 2023, 7:12 AM

LGTM

This revision is now accepted and ready to land.Apr 26 2023, 7:12 AM
arsenm accepted this revision.Apr 26 2023, 7:45 AM
This revision was automatically updated to reflect the committed changes.