This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU/SI: move SMRD to flat if UseFlatForGlobal is true
AbandonedPublic

Authored by cfang on Feb 9 2016, 2:17 PM.

Details

Summary

For a SMRD, if SBase is a Vector register, we need to move it to VAlu. On Vi+,
addr64 buffer loads are not supported, so we will have to use flat loads instead.

This patch implements this "Move".

Diff Detail

Event Timeline

cfang updated this revision to Diff 47365.Feb 9 2016, 2:17 PM
cfang retitled this revision from to AMDGPU/SI: move SMRD to flat if UseFlatForGlobal is true.
cfang updated this object.
cfang added reviewers: tstellarAMD, arsenm.
cfang added subscribers: llvm-commits, arsenm.
lib/Target/AMDGPU/SIInstrInfo.cpp
2327–2341

It would be really great if we could use the InstrMappings in Tablegen to generate this, but I guess it is a pretty small table.

You should simplify it though, since we have multiple case statements returning the same value.

2366

We also want to do this on VI when the original opcode is an addr64..

2381

You should use getNamedOperand here instead of indexing by number.

2386

Same here and a few other places.

2410–2412

On SI/CI the immediate offset is in dowrds, but on VI it is in bytes, so I think this calculation will be wrong on SI/CI.

I recommend creating a helper function to extract the: base pointer, reg offset and/or immediate offset from the SMRD instruction. This way you could share code from the non-floatForGlobal path, which already handles the immediate conversion correctly.

test/CodeGen/AMDGPU/salu-to-valu.ll
55–60

I think you should add more test cases testing the edge cases for the immediate offsets.

arsenm edited edge metadata.Feb 10 2016, 11:11 AM

Can you split this into functions? We might want to re-use this in other places

arsenm added inline comments.Feb 10 2016, 11:14 AM
test/CodeGen/AMDGPU/salu-to-valu.ll
55–60

This test should also have a VI run line added

cfang added a comment.Feb 11 2016, 1:59 PM

Can you split this into functions? We might want to re-use this in other places

This is to translate smrd ( with sbase in VGPR) to flat. I can not what other places need this translation.
I would factor out to a function when we are working on a case that need re-use.

cfang updated this revision to Diff 47728.Feb 11 2016, 2:02 PM
cfang edited edge metadata.

Update the patch based on Tom's review.

lib/Target/AMDGPU/SIInstrInfo.cpp
2379–2397

This code is very similar to what we have in the non-FlatForGlobal path. Can we put this code into its own function so we can share it between the two paths.

Can you split this into functions? We might want to re-use this in other places

This is to translate smrd ( with sbase in VGPR) to flat. I can not what other places need this translation.
I would factor out to a function when we are working on a case that need re-use.

Functions are also more readable. The various moveToVALU instructions are already too big

arsenm added inline comments.Feb 12 2016, 5:17 PM
lib/Target/AMDGPU/SIInstrInfo.cpp
2366

I think we should add a hasAddr64() in AMDGPUSubtarget which would return this

2401

Extra spaces around HasOffset

cfang added inline comments.Feb 15 2016, 4:37 PM
lib/Target/AMDGPU/SIInstrInfo.cpp
2379–2397

Yes, the code is similar on both paths. But to me, it is not that easy for them to share the same code.

I can introduce a function to return the immediate and register offsets for a smrd instruction. but I still have to handle
the immediate separately. Also, for the flat path, I want to save the 64-bit addition when the immediate offset is 0.
This will make the code sharing a little "ugly".

I've been discussing a different issue with Nicoli, and I'm wondering if it would be better just to insert v_readfirstlane instructions to copy the pointer back to SGPRs rather than using a VMEM instruction. This would simplify the code a lot.

Does D17305 help fix the problem?

arsenm added a comment.Mar 1 2016, 6:32 PM

Can this be dropped now? Maybe the test is still useful?

cfang added a subscriber: cfang.Mar 3 2016, 10:55 AM

I think this can be dropped, and the test case has no additional value since
it has been derived from other test.

Thanks;

Changpeng

Can you close the revision then?

cfang abandoned this revision.Mar 3 2016, 1:25 PM

Close it because it is no longer valid.