[llvm] [AMDGPU] Support merging 16-bit TBUFFER load/store instruction (PR #145078)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 23 01:32:11 PDT 2025
================
@@ -1040,32 +1040,58 @@ bool SILoadStoreOptimizer::offsetsCanBeCombined(CombineInfo &CI,
if (CI.Offset == Paired.Offset)
return false;
+ // Use 2-byte element size if both tbuffer formats are 16-bit.
+ unsigned EltSize = CI.EltSize;
+ auto Has16BitComponents = [&](unsigned Format) -> bool {
+ const auto *Info = AMDGPU::getGcnBufferFormatInfo(Format, STI);
+ return Info && Info->BitsPerComp == 16;
+ };
+
+ if ((CI.InstClass == TBUFFER_LOAD || CI.InstClass == TBUFFER_STORE)) {
+ // TODO: Support merging 8-bit tbuffer load/store instructions
+ if (Has16BitComponents(CI.Format) && Has16BitComponents(Paired.Format))
+ EltSize = 2;
+ }
+
// This won't be valid if the offset isn't aligned.
- if ((CI.Offset % CI.EltSize != 0) || (Paired.Offset % CI.EltSize != 0))
+ if ((CI.Offset % EltSize != 0) || (Paired.Offset % EltSize != 0))
return false;
if (CI.InstClass == TBUFFER_LOAD || CI.InstClass == TBUFFER_STORE) {
- const llvm::AMDGPU::GcnBufferFormatInfo *Info0 =
- llvm::AMDGPU::getGcnBufferFormatInfo(CI.Format, STI);
+ const AMDGPU::GcnBufferFormatInfo *Info0 =
+ AMDGPU::getGcnBufferFormatInfo(CI.Format, STI);
if (!Info0)
return false;
- const llvm::AMDGPU::GcnBufferFormatInfo *Info1 =
- llvm::AMDGPU::getGcnBufferFormatInfo(Paired.Format, STI);
+ const AMDGPU::GcnBufferFormatInfo *Info1 =
+ AMDGPU::getGcnBufferFormatInfo(Paired.Format, STI);
if (!Info1)
return false;
if (Info0->BitsPerComp != Info1->BitsPerComp ||
Info0->NumFormat != Info1->NumFormat)
return false;
- // TODO: Should be possible to support more formats, but if format loads
- // are not dword-aligned, the merged load might not be valid.
----------------
jayfoad wrote:
Will your patch merge two 16-bit loads at offsets 2 and 4, into a single 32-bit load at offset 2?
If it does that then the merged load is not dword aligned. Is that allowed?
https://github.com/llvm/llvm-project/pull/145078
More information about the llvm-commits
mailing list