This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Fix Vreg_1 PHI lowering in SILowerI1Copies.
ClosedPublic

Authored by cdevadas on Oct 18 2019, 10:06 AM.

Details

Summary

There is a minor flaw in the implementation of function lowerPhis.
This function replaces values of regclass Vreg_1 (boolean values)
involved in PHIs into an SGPR. Currently it iterates over the MBBs
and performs an inplace lowering of PHIs and fails to lower any
incoming value that itself is another PHI of Vreg_1 regclass.
The failure occurs only when the MBB where the incoming PHI value
belongs is not visited/lowered yet.

To fix this problem, collect all Vreg_1 PHIs upfront and then
perform the lowering.

Diff Detail

Event Timeline

cdevadas created this revision.Oct 18 2019, 10:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 18 2019, 10:06 AM
arsenm added inline comments.Oct 18 2019, 10:46 AM
lib/Target/AMDGPU/SILowerI1Copies.cpp
552 ↗(On Diff #225656)

Can we just use RPO order instead?

test/CodeGen/AMDGPU/i1_copy_phi_with_phi_incoming_value.ll
55–63 ↗(On Diff #225656)

This test is a bit complicated, and should also not use anonymous values. You should be able to reduce it further

cdevadas marked 2 inline comments as done.Oct 18 2019, 11:08 AM
cdevadas added inline comments.
lib/Target/AMDGPU/SILowerI1Copies.cpp
552 ↗(On Diff #225656)

This change ensures that all PHI nodes will be lowered. I don't see a problem if we don't visit them in order. Any advantage of using RPO here?

test/CodeGen/AMDGPU/i1_copy_phi_with_phi_incoming_value.ll
55–63 ↗(On Diff #225656)

Sure. I will try to reduce the test.

cdevadas updated this revision to Diff 225901.Oct 21 2019, 9:21 AM

Used RPO traversal instead of default MBB traversal + reduced the unit-test.

cdevadas updated this revision to Diff 225902.Oct 21 2019, 9:29 AM

A minor change in the test case.

@nhaehnle didn't want to use RPO for some reason last time this fixed a problem here. Which way do you prefer here?

cdevadas updated this revision to Diff 225997.Oct 21 2019, 10:18 PM

Avoiding RPO traversal. PHI uses can be circular in some cases.

Right, I don't think RPO hurts, but I also didn't (and still don't) see how it would help due to the possible circularity between PHIs, so I'd rather stick to the simpler iteration. Otherwise somebody looking at the code later may think the RPO is important for some aspect of the algorithm.

The code change LGTM. For the test, I wonder if it wouldn't be better served as a MIR test.

cdevadas updated this revision to Diff 226058.Oct 22 2019, 10:45 AM

Added the MIR test.

arsenm accepted this revision.Oct 25 2019, 11:28 AM

LGTM

This revision is now accepted and ready to land.Oct 25 2019, 11:28 AM
This revision was automatically updated to reflect the committed changes.