https://github.com/yxsamliu created https://github.com/llvm/llvm-project/pull/246922
LLVM #196505 removed the 16-byte array alignment rule that AMDGPU inherited from the x86-64 MSVC host. In a gfx1100 WMMA example, an LDS array dropped from 16-byte to 2-byte alignment. A read changed from four `ds_load_2addr_b32` instructions to two `ds_load_b128` instructions. The vLLM W4A16 prefill GEMM took 6.10 ms on Windows and 1.57 ms with explicit 4-byte alignment using the same compiler. Restore the old device alignment rule. It aligns the array's starting address after struct layout and array element spacing are determined. https://github.com/llvm/llvm-project/pull/196505 https://github.com/ROCm/TheRock/issues/10272#issuecomment-7236349933 AI assisted. >From 7b0f5717345c886a5299770a32034f84fd1ddda9 Mon Sep 17 00:00:00 2001 From: "Yaxun (Sam) Liu" <[email protected]> Date: Sat, 28 Nov 2026 14:22:38 +0000 Subject: [PATCH] [clang][AMDGPU] Restore large-array alignment for Windows HIP LLVM #196505 removed the 16-byte array alignment rule that AMDGPU inherited from the x86-64 MSVC host. In a gfx1100 WMMA example, an LDS array dropped from 16-byte to 2-byte alignment. A read changed from four `ds_load_2addr_b32` instructions to two `ds_load_b128` instructions. The vLLM W4A16 prefill GEMM took 6.10 ms on Windows and 1.57 ms with explicit 4-byte alignment using the same compiler. Restore the old device alignment rule. It aligns the array's starting address after struct layout and array element spacing are determined. https://github.com/llvm/llvm-project/pull/196505 https://github.com/ROCm/TheRock/issues/10272#issuecomment-7236349933 AI assisted. --- clang/lib/Basic/Targets/AMDGPU.cpp | 10 +++++++++ .../amdgpu-shared-array-alignment.hip | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 clang/test/CodeGenHIP/amdgpu-shared-array-alignment.hip diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp index c3e6f8bbcafa8a..53dafb1c6620e6 100644 --- a/clang/lib/Basic/Targets/AMDGPU.cpp +++ b/clang/lib/Basic/Targets/AMDGPU.cpp @@ -355,6 +355,16 @@ void AMDGPUTargetInfo::setAuxTarget(const TargetInfo *Aux) { Float128Format = SaveFloat128Format; LongDoubleWidth = SaveLongDoubleWidth; LongDoubleAlign = SaveLongDoubleAlign; + + // Keep the AMDGCN large-array alignment used before the x86-64 MSVC + // target switched to its own minimum global alignment rules. + const llvm::Triple &AuxTriple = Aux->getTriple(); + if (getTriple().isAMDGCN() && AuxTriple.getArch() == llvm::Triple::x86_64 && + AuxTriple.isWindowsMSVCEnvironment()) { + LargeArrayMinWidth = 128; + LargeArrayAlign = 128; + } + // For certain builtin types support on the host target, claim they are // support to pass the compilation of the host code during the device-side // compilation. diff --git a/clang/test/CodeGenHIP/amdgpu-shared-array-alignment.hip b/clang/test/CodeGenHIP/amdgpu-shared-array-alignment.hip new file mode 100644 index 00000000000000..b945d3a91700e4 --- /dev/null +++ b/clang/test/CodeGenHIP/amdgpu-shared-array-alignment.hip @@ -0,0 +1,21 @@ +// NOTE: Do not autogenerate. Check only the alignment of the LDS arrays. +// REQUIRES: amdgpu-registered-target +// RUN: %clang_cc1 -triple amdgpu11.00-amd-amdhsa -aux-triple x86_64-pc-windows-msvc \ +// RUN: -fcuda-is-device -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple amdgpu11.00-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu \ +// RUN: -fcuda-is-device -emit-llvm -o - %s | FileCheck %s + +// CHECK-DAG: @{{.*}}small = internal addrspace(3) global [7 x half] undef, align 2{{$}} +// CHECK-DAG: @{{.*}}large = internal addrspace(3) global [8 x half] undef, align 16{{$}} +// CHECK-DAG: @{{.*}}explicit_align = internal addrspace(3) global [8 x half] undef, align 4{{$}} + +__attribute__((device)) void use(_Float16 *); + +__attribute__((global)) void kernel() { + __attribute__((shared)) _Float16 small[7]; + __attribute__((shared)) _Float16 large[8]; + __attribute__((shared, aligned(4))) _Float16 explicit_align[8]; + use(small); + use(large); + use(explicit_align); +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
