[llvm] [AMDGPU] Add target feature require-naturally-aligned-buffer-access (PR #115479)

Piotr Sobczak via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 21 07:48:42 PST 2024


================
@@ -1840,6 +1840,20 @@ bool SITargetLowering::allowsMisalignedMemoryAccessesImpl(
            Subtarget->hasUnalignedBufferAccessEnabled();
   }
 
+  // Check natural alignment of buffer if the target requires it. This is needed
+  // only if robust out-of-bounds guarantees are needed. Normally hardware will
+  // ensure proper out-of-bounds behavior, but in the edge case where an access
+  // starts out-of-bounds and then enter in-bounds, the entire access would be
+  // treated as out-of-bounds. Requiring the natural alignment avoids the
+  // problem.
+  if (AddrSpace == AMDGPUAS::BUFFER_FAT_POINTER ||
+      AddrSpace == AMDGPUAS::BUFFER_RESOURCE ||
+      AddrSpace == AMDGPUAS::BUFFER_STRIDED_POINTER) {
+    if (Subtarget->hasRequireNaturallyAlignedBufferAccess() &&
+        Alignment < Align(PowerOf2Ceil(divideCeil(Size, 8))))
----------------
piotrAMD wrote:

Hmm, not sure, because I do not call alignTo here, just calculate the required alignment.

https://github.com/llvm/llvm-project/pull/115479


More information about the llvm-commits mailing list