This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU][GlobalISel] Improve constant offset lookup for llvm.amdgcn.s.buffer
Needs ReviewPublic

Authored by mbrkusanin on Mar 5 2021, 6:09 AM.

Details

Reviewers
foad
arsenm
Summary

Looking up constant offset for this intrinsic is done during RegBankSelect
so the constant might find itself behind a copy from sgpr to vgpr.

Diff Detail

Event Timeline

mbrkusanin created this revision.Mar 5 2021, 6:09 AM
mbrkusanin requested review of this revision.Mar 5 2021, 6:09 AM
arsenm added inline comments.Mar 5 2021, 6:17 AM
llvm/lib/Target/AMDGPU/AMDGPUGlobalISelUtils.cpp
51

This shouldn't add a second match pattern for a copy. That should be hidden away somehow. In this case I'd say the problem is regbankselect isn't picking the correct bank for the constant in the first place since we don't consider the users right now. We've been working around this on a case by case basis, but I think we should try to fix this.

Also arguably mi_match should look through copies, although in the presence of cross reg bank copies that's more questionable

arsenm requested changes to this revision.Mar 30 2021, 3:20 PM
This revision now requires changes to proceed.Mar 30 2021, 3:20 PM

I revisited this again to try to find a way to eliminate these cross reg bank copies but I wasn't able to find an efficient solution. Looking through uses of dst of G_CONSTANT at the time of selecting a bank for that instruction does not help since RegBank is not working backwards.

One idea that does work is to instead of making a cross reg bank copy to a constant to simply recreate a new G_CONSTANT with required bank (change is in RegBankSelect::repairReg). This can help with the current problem but produces less optimal solutions in a lot of tests. In some cases instead of an SGPR, an extra VPGR will be used instead. And in cases where same constant needs to be used as both SGPR and VGPR there can also be an additional s/v_mov instruction.

Here we can at least hide copy check inside matcher.