This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU][SelectionDAG] Don't combine uniform multiplies to MUL_[UI]24
ClosedPublic

Authored by foad on Feb 19 2021, 9:29 AM.

Details

Summary

Prefer to keep uniform (non-divergent) multiplies on the scalar ALU when
possible. This significantly improves some game cases by eliminating
v_readfirstlane instructions when the result feeds into a scalar
operation, like the address calculation for a scalar load or store.

Since isDivergent is only an approximation of whether a value is in
SGPRs, it can potentially regress some situations where a uniform value
ends up in a VGPR. These should be rare in real code, although the test
changes do contain a number of examples.

Most of the test changes are just using s_mul instead of v_mul/mad which
is generally better for both register pressure and latency (at least on
GFX10 where sgpr pressure doesn't affect occupancy and vector ALU
instructions have significantly longer latency than scalar ALU). Some
R600 tests now use MULLO_INT instead of MUL_UINT24.

GlobalISel appears to handle more scenarios in the desirable way,
although it can also be thrown off and fails to select the 24-bit
multiplies in some cases.

Alternative solution considered and rejected was to allow selecting
MUL_[UI]24 to S_MUL_I32. I've rejected this because the definition of
those SD operations works is don't-care on the most significant 8 bits,
and this fact is used in some combines via SimplifyDemandedBits.

Based on a patch by Nicolai Hähnle.

Diff Detail

Event Timeline

foad created this revision.Feb 19 2021, 9:29 AM
foad requested review of this revision.Feb 19 2021, 9:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 19 2021, 9:29 AM
foad added a reviewer: alex-t.Feb 23 2021, 6:00 AM
arsenm accepted this revision.Feb 23 2021, 6:04 AM

GlobalISel doesn't implement the 24-bit matching at all right now. It only is relying on the IR version

This revision is now accepted and ready to land.Feb 23 2021, 6:04 AM
This revision was landed with ongoing or failed builds.Feb 23 2021, 7:48 AM
This revision was automatically updated to reflect the committed changes.