[clang] [PowerPC] make `_Complex` ABI GCC-compatible (PR #208917)
Matt Turner via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 29 08:49:37 PST 2026
================
@@ -427,9 +441,94 @@ CharUnits PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
return CharUnits::fromQuantity(4);
}
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyComplexType(QualType Ty) const {
+ assert(Ty->isAnyComplexType() && "not a complex type");
+
+ uint64_t Size = getContext().getTypeSize(Ty);
+ llvm::LLVMContext &VMC = getVMContext();
+ llvm::Type *I32 = llvm::Type::getInt32Ty(VMC);
+
+ // Coerce to an integer for _Complex char and _Complex short.
+ if (Size <= GPRBits)
+ return ABIArgInfo::getDirect(llvm::IntegerType::get(VMC, Size));
+
+ // Coerce to a vector <N x i32> for _Complex float and _Complex int.
+ // A vector gives this the correct 8-byte register alignment.
+ if (Size == 2 * GPRBits)
+ return ABIArgInfo::getDirect(llvm::FixedVectorType::get(I32, 2));
----------------
mattst88 wrote:
With AltiVec this goes in a vector register. The backend widens `<2 x i32>` to
`v4i32`, so with `-maltivec` or `-mcpu=7450` llc passes and returns it in v2:
```llvm
target triple = "powerpc-unknown-linux-gnu"
declare void @g(i32, <2 x i32>)
define void @caller() {
call void @g(i32 1, <2 x i32> <i32 2, i32 3>)
ret void
}
define <2 x i32> @r() {
ret <2 x i32> <i32 1, i32 2>
}
```
`llc -mattr=+altivec` loads the argument with `lvx 2, ...` and returns `@r` in
v2. GCC passes `g(1, 2.0f + 3.0fi)` in r3 and r5/r6, and returns a
`_Complex float` in r3/r4, with or without `-maltivec`.
An `i64` is aligned to an even register pair by the calling convention on any
subtarget, so the vector can go:
```c++
if (Size <= 2 * GPRBits)
return ABIArgInfo::getDirect(llvm::IntegerType::get(VMC, Size));
```
https://github.com/llvm/llvm-project/pull/208917
More information about the cfe-commits
mailing list