[all-commits] [llvm/llvm-project] 50b859: [AMDGPU] Stop coercing structs with FP and int fie...
Addmisol via All-commits
all-commits at lists.llvm.org
Fri Apr 17 10:12:14 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 50b859cca1ccf7d174ee61a8a130ae14220209e4
https://github.com/llvm/llvm-project/commit/50b859cca1ccf7d174ee61a8a130ae14220209e4
Author: Addmisol <addmisol9 at gmail.com>
Date: 2026-04-17 (Fri, 17 Apr 2026)
Changed paths:
M clang/lib/CodeGen/Targets/AMDGPU.cpp
A clang/test/CodeGen/amdgpu-abi-struct-coerce.c
M clang/test/CodeGen/amdgpu-variadic-call.c
M clang/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
M clang/test/Headers/amdgcn-openmp-device-math-complex.c
Log Message:
-----------
[AMDGPU] Stop coercing structs with FP and int fields to integer arrays (#185083)
Fixes #184150
This PR fixes the ABI lowering code for small aggregates (≤64 bits) on
AMDGPU targets to selectively coerce based on element types:
- Structs containing only sub-32-bit integers (char, short): Continue to
coerce to i16/i32/[2 x i32] for efficient register packing
- Structs containing floats or full-sized integers (i32, i64, float,
double): Preserve original types using ABIArgInfo::getDirect() without
coercion
Previously, ALL small aggregates were unconditionally coerced to integer
types. A struct like { float, int } would be lowered to [2 x i32],
losing the floating-point type information. This prevented attaching
FP-specific attributes like nofpclass to the float
component.
Changes
- clang/lib/CodeGen/Targets/AMDGPU.cpp: Added
containsOnlyPackableIntegerTypes() helper function that recursively
checks if an aggregate contains only sub-32-bit integer types. Updated
classifyReturnType and classifyArgumentType to use this helper - only
coercing
aggregates that contain exclusively small integers, while preserving
types for aggregates containing floats or full-sized integers.
- clang/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl: Updated expected
output to reflect that char-only structs are still coerced (e.g.,
struct_char_x8 -> [2 x i32]) while preserving correct behavior.
- clang/test/CodeGen/amdgpu-abi-struct-coerce.c: Added test coverage for
various struct types including mixed float/int fields, demonstrating the
selective coercion behavior.
Before/After
// Struct with float - NOW preserves types
typedef struct { float f; int i; } fp_int_pair;
Before: define [2 x i32] @ foo([2 x i32] %x.coerce)
After: define %struct.fp_int_pair @ foo(float %x.coerce0, i32
%x.coerce1)
// Struct with only small integers - STILL coerced for efficiency
typedef struct { char a, b, c, d, e, f, g, h; } eight_chars;
Before: define [2 x i32] @ bar([2 x i32] %x.coerce)
After: define [2 x i32] @ bar([2 x i32] %x.coerce) // Unchanged
Test Plan
- Updated existing ABI tests in amdgpu-abi-struct-coerce.cl
- Added new test amdgpu-abi-struct-coerce.c for mixed FP/int structs
- Updated affected OpenMP complex math header tests
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list