This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Improve the lowering of raw_buffer_load_{i8,i16} and struct_buffer_load_{i8,i16} intrinsics
ClosedPublic

Authored by kmitropoulou on Feb 17 2023, 6:03 PM.

Details

Summary

Currently, raw_buffer_load_{i8,i16} and struct_buffer_load_{i8,i16}
intrinsics are lowered as buffer_load_{u8,u16}. This patch combines
buffer_load_{u8,u16} and sign extension instructions in order to
generate buffer_load_{i8,i16} instructions.

Diff Detail

Event Timeline

kmitropoulou created this revision.Feb 17 2023, 6:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2023, 6:03 PM
kmitropoulou requested review of this revision.Feb 17 2023, 6:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2023, 6:03 PM

Updating D144313: [AMDGPU] Improve the lowering of buffer_load_{u8, u16} intrinsics.

Updating D144313: [AMDGPU] Improve the lowering of buffer_load_{u8, u16} intrinsics.

kmitropoulou retitled this revision from [AMDGPU] Improve the lowering of buffer_load_{u8, u16} intrinsics. to [AMDGPU] Improve the lowering of raw_buffer_load_{i8,i16} and struct_buffer_load_{i8,i16} intrinsics.Feb 17 2023, 6:14 PM
kmitropoulou edited the summary of this revision. (Show Details)
kmitropoulou edited the summary of this revision. (Show Details)

Updating D144313: [AMDGPU] Improve the lowering of raw_buffer_load_{i8,i16} and struct_buffer_load_{i8,i16} intrinsics

foad added inline comments.Feb 20 2023, 2:14 AM
llvm/lib/Target/AMDGPU/AMDGPUCombinerHelper.cpp
399 ↗(On Diff #498544)

You need to check that SubwordBufferLoad has no other uses.

Instead of creating a new instruction, you can modify it in-place using SubwordBufferLoad->setDesc and SubwordBufferLoad->getOperand(0).setReg.

llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
423–424

Instead of calling applyCombineSignExtendInReg here, please declare the new combine in AMDGPUCombine.td so it will be called from the autogenerated tryCombineAll.

arsenm added inline comments.Feb 20 2023, 4:02 AM
llvm/lib/Target/AMDGPU/AMDGPUCombinerHelper.cpp
391 ↗(On Diff #498544)

getVRegDef?

393 ↗(On Diff #498544)

The calling combiner code should really set the insert point for you, not sure why we still don't do that

kmitropoulou marked 3 inline comments as done.

Updating D144313: [AMDGPU] Improve the lowering of raw_buffer_load_{i8,i16} and struct_buffer_load_{i8,i16} intrinsics

kmitropoulou added inline comments.Feb 20 2023, 7:34 PM
llvm/lib/Target/AMDGPU/AMDGPUCombinerHelper.cpp
393 ↗(On Diff #498544)

I checked the combineMachineInstrs() in Combiner.cpp and it does not set an insertion point for the builder. The same happens in combine() in AMDGPUPostLegalizerCombiner.cpp . So, I assume it is intentional in case you need to add instructions at different points.

kmitropoulou marked an inline comment as done.Feb 20 2023, 7:34 PM
foad added a comment.Feb 21 2023, 1:17 AM

Looks good with a few suggested changes.

llvm/lib/Target/AMDGPU/AMDGPUCombinerHelper.cpp
400–404 ↗(On Diff #499015)
411–412 ↗(On Diff #499015)

Don't need these two lines. SubwordBufferLoad is passed in as an argument now.

416 ↗(On Diff #499015)

I think all this new code should probably live in AMDGPUPostLegalizerCombinerHelper instead of AMDGPUCombinerHelper, and you should add TII as a member variable in AMDGPUPostLegalizerCombinerHelper following the example of AMDGPURegBankCombinerHelper.

kmitropoulou marked 2 inline comments as done.

Updating D144313: [AMDGPU] Improve the lowering of raw_buffer_load_{i8,i16} and struct_buffer_load_{i8,i16} intrinsics

kmitropoulou marked an inline comment as done.Feb 21 2023, 12:55 PM
foad accepted this revision.Feb 22 2023, 8:55 AM

LGTM, thanks!

This revision is now accepted and ready to land.Feb 22 2023, 8:55 AM

Updating D144313: [AMDGPU] Improve the lowering of raw_buffer_load_{i8,i16} and struct_buffer_load_{i8,i16} intrinsics

This revision was landed with ongoing or failed builds.Feb 22 2023, 9:02 AM
This revision was automatically updated to reflect the committed changes.