This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU: Fix infinite searches in SIFixSGPRCopies
ClosedPublic

Authored by kerbowa on Oct 15 2019, 12:11 AM.

Details

Summary

Two conditions could lead to infinite loops when processing PHI nodes in
SIFixSGPRCopies.

The first condition involves a REG_SEQUENCE that uses registers defined by both
a PHI and a COPY.

The second condition arises when a physical register is copied to a virtual
register which is then used in a PHI node. If the same virtual register is
copied to the same physical register, the result is an endless loop.

%0:sgpr_64 = COPY $sgpr0_sgpr1
%2 = PHI %0, %bb.0, %1, %bb.1
$sgpr0_sgpr1 = COPY %0

Diff Detail

Event Timeline

kerbowa created this revision.Oct 15 2019, 12:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 15 2019, 12:11 AM
rampitec added inline comments.Oct 15 2019, 1:26 AM
llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
700

SmallSet maybe instead?

Thanks for tracking that down. I agree with Stas that SmallSet should be a better choice here. Also some minor comments on the tests, apart from that looks good to me.

llvm/test/CodeGen/AMDGPU/fix-sgpr-copies.mir
70–73

You should be able to remove this and instead write %2:sgpr_64 = PHI ... below.

99–103

Analogous to above, you should be able to remove this by adding the register class constraints to the defining instruction below.

kerbowa updated this revision to Diff 225084.Oct 15 2019, 11:02 AM

Incorporate reviewer comments.

kerbowa updated this revision to Diff 225085.Oct 15 2019, 11:08 AM

Cleanup test.

Harbormaster completed remote builds in B39594: Diff 225085.
This revision is now accepted and ready to land.Oct 15 2019, 11:13 AM
arsenm added inline comments.Oct 15 2019, 12:21 PM
llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
699–702

Worklist is a SetVector already, so why does this need another set?

kerbowa marked an inline comment as done.Oct 15 2019, 12:44 PM
kerbowa added inline comments.
llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
699–702

Instructions are removed from the worklist. It's to avoid adding the same ones again.

This revision was automatically updated to reflect the committed changes.