This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Add missing use check in SIOptimizeExecMasking pass.
ClosedPublic

Authored by tsymalla on Mar 31 2022, 3:32 AM.

Details

Summary

Whenever a v_cmp, s_and_saveexec instruction sequence shall be
transformed to an equivalent s_mov, v_cmpx sequence, it needs
to be detected if the v_cmp target register is used between
the two instructions as the v_cmp result gets omitted by
using the v_cmpx instruction, resulting in invalid code.

Diff Detail

Event Timeline

tsymalla created this revision.Mar 31 2022, 3:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 31 2022, 3:32 AM
tsymalla requested review of this revision.Mar 31 2022, 3:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 31 2022, 3:32 AM
tsymalla updated this revision to Diff 419388.Mar 31 2022, 3:41 AM

Fix start iterator usage.

tsymalla updated this revision to Diff 419394.Mar 31 2022, 4:08 AM

Improve boolean flag usage for register liveness checks.

tsymalla updated this revision to Diff 419396.Mar 31 2022, 4:25 AM

Remove .s file from commit.

foad accepted this revision.Mar 31 2022, 6:16 AM

Looks OK as it fixes a bug, but I think the liveness checking could be cleaned up as noted inline.

llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
414–422

I'm not sure that the isRegisterInUseBetween and isRegisterInUseAfter helper functions are actually making this code any simpler, or easier to understand.

The conditions you really want to check are:

  1. is VCmpDest->getReg() live immediately after SaveExec? You can do this with LivePhysRegs, and this check would replace both the isLiveOut check (line 414) and the isRegisterInUseAfter check.
  2. is VCmpDest->getReg() used by an instruction between *VCmp and SaveExec? You don't need any kind of liveness for this check, you can just examine the operands of every instruction in that range.
This revision is now accepted and ready to land.Mar 31 2022, 6:16 AM
This revision was landed with ongoing or failed builds.Mar 31 2022, 10:25 AM
This revision was automatically updated to reflect the committed changes.