Skip to content

Commit

Permalink
[clang][PowerPC] Add flag to enable compatibility with GNU for comple…
Browse files Browse the repository at this point in the history
…x arguments

Fixes : #56023

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
  • Loading branch information
Long5hot committed May 6, 2024
1 parent cc5fe4a commit 473e188
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 227 deletions.
6 changes: 3 additions & 3 deletions clang/lib/CodeGen/Targets/PPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
bool IsSoftFloatABI;
bool IsRetSmallStructInRegABI;
// Size of GPR in bits.
static const unsigned RegLen = 32;
static const unsigned GPRBits = 32;
static const int ArgGPRsNum = 8;

CharUnits getParamTypeAlignment(QualType Ty) const;
Expand Down Expand Up @@ -455,8 +455,8 @@ ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
if (TypeSize == 64 && ArgGPRsLeft % 2 == 1)
--ArgGPRsLeft;

if (TypeSize <= RegLen * ArgGPRsLeft) {
ArgGPRsLeft -= TypeSize / RegLen;
if (TypeSize <= GPRBits * ArgGPRsLeft) {
ArgGPRsLeft -= TypeSize / GPRBits;
if (IsComplex)
return handleComplex(TypeSize);
}
Expand Down
24 changes: 13 additions & 11 deletions clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// RUN: %clang_cc1 -triple powerpc-unknown-linux-gnu -fcomplex-ppc-gnu-abi \
// RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-GNU



// CHECK-DEF-LABEL: define dso_local void @_cfloat
// CHECK-DEF-SAME: (ptr dead_on_unwind noalias writable sret({ float, float }) align 4 [[AGG_RESULT:%.*]], ptr noundef byval({ float, float }) align 4 [[X:%.*]]) #[[ATTR0:[0-9]+]] {
// CHECK-DEF-NEXT: entry:
Expand All @@ -25,7 +27,7 @@
// CHECK-DEF-NEXT: store float [[AGG_RESULT_REAL]], ptr [[AGG_RESULT_REALP3]], align 4
// CHECK-DEF-NEXT: store float [[AGG_RESULT_IMAG]], ptr [[AGG_RESULT_IMAGP4]], align 4
// CHECK-DEF-NEXT: ret void
//

// CHECK-GNU-LABEL: define dso_local [1 x i64] @_cfloat
// CHECK-GNU-SAME: ([1 x i64] noundef [[X_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
// CHECK-GNU-NEXT: entry:
Expand All @@ -42,7 +44,7 @@
// CHECK-GNU-NEXT: store float [[X_IMAG]], ptr [[RETVAL_IMAGP]], align 4
// CHECK-GNU-NEXT: [[TMP0:%.*]] = load [1 x i64], ptr [[RETVAL]], align 4
// CHECK-GNU-NEXT: ret [1 x i64] [[TMP0]]
//

_Complex float _cfloat(_Complex float x) {
return x;
}
Expand All @@ -67,7 +69,7 @@ _Complex float _cfloat(_Complex float x) {
// CHECK-DEF-NEXT: store double [[AGG_RESULT_REAL]], ptr [[AGG_RESULT_REALP3]], align 8
// CHECK-DEF-NEXT: store double [[AGG_RESULT_IMAG]], ptr [[AGG_RESULT_IMAGP4]], align 8
// CHECK-DEF-NEXT: ret void
//

// CHECK-GNU-LABEL: define dso_local [4 x i32] @_cdouble
// CHECK-GNU-SAME: ([4 x i32] noundef [[X_COERCE:%.*]]) #[[ATTR0]] {
// CHECK-GNU-NEXT: entry:
Expand Down Expand Up @@ -109,7 +111,7 @@ _Complex double _cdouble(_Complex double x) {
// CHECK-DEF-NEXT: store ppc_fp128 [[AGG_RESULT_REAL]], ptr [[AGG_RESULT_REALP3]], align 16
// CHECK-DEF-NEXT: store ppc_fp128 [[AGG_RESULT_IMAG]], ptr [[AGG_RESULT_IMAGP4]], align 16
// CHECK-DEF-NEXT: ret void
//

// CHECK-GNU-LABEL: define dso_local [8 x i32] @_cldouble
// CHECK-GNU-SAME: ([8 x i32] noundef [[X_COERCE:%.*]]) #[[ATTR0]] {
// CHECK-GNU-NEXT: entry:
Expand All @@ -126,7 +128,7 @@ _Complex double _cdouble(_Complex double x) {
// CHECK-GNU-NEXT: store ppc_fp128 [[X_IMAG]], ptr [[RETVAL_IMAGP]], align 16
// CHECK-GNU-NEXT: [[TMP0:%.*]] = load [8 x i32], ptr [[RETVAL]], align 16
// CHECK-GNU-NEXT: ret [8 x i32] [[TMP0]]
//

_Complex long double _cldouble(_Complex long double x) {
return x;
}
Expand Down Expand Up @@ -164,7 +166,7 @@ _Complex long double _cldouble(_Complex long double x) {
// CHECK-DEF-NEXT: store double [[AGG_RESULT_REAL]], ptr [[AGG_RESULT_REALP3]], align 8
// CHECK-DEF-NEXT: store double [[AGG_RESULT_IMAG]], ptr [[AGG_RESULT_IMAGP4]], align 8
// CHECK-DEF-NEXT: ret void
//

// CHECK-GNU-LABEL: define dso_local [4 x i32] @testComplexDouble
// CHECK-GNU-SAME: (i32 noundef [[W:%.*]], [1 x i64] noundef [[X_COERCE:%.*]], [4 x i32] noundef [[Z_COERCE:%.*]]) #[[ATTR0]] {
// CHECK-GNU-NEXT: entry:
Expand Down Expand Up @@ -198,7 +200,7 @@ _Complex long double _cldouble(_Complex long double x) {
// CHECK-GNU-NEXT: store double [[COERCE1_IMAG]], ptr [[RETVAL_IMAGP]], align 8
// CHECK-GNU-NEXT: [[TMP1:%.*]] = load [4 x i32], ptr [[RETVAL]], align 8
// CHECK-GNU-NEXT: ret [4 x i32] [[TMP1]]
//

_Complex double testComplexDouble(int w, _Complex float x, _Complex double z)
{
return _cdouble(z);
Expand Down Expand Up @@ -249,7 +251,7 @@ _Complex double testComplexDouble(int w, _Complex float x, _Complex double z)
// CHECK-DEF-NEXT: store double [[AGG_RESULT_REAL]], ptr [[AGG_RESULT_REALP4]], align 8
// CHECK-DEF-NEXT: store double [[AGG_RESULT_IMAG]], ptr [[AGG_RESULT_IMAGP5]], align 8
// CHECK-DEF-NEXT: ret void
//

// CHECK-GNU-LABEL: define dso_local [4 x i32] @checkComplexDoubleOnStack
// CHECK-GNU-SAME: (i32 noundef [[X1:%.*]], [1 x i64] noundef [[CF_COERCE:%.*]], i32 noundef [[X2:%.*]], ptr noundef byval({ double, double }) align 8 [[CD:%.*]]) #[[ATTR0]] {
// CHECK-GNU-NEXT: entry:
Expand Down Expand Up @@ -294,7 +296,7 @@ _Complex double testComplexDouble(int w, _Complex float x, _Complex double z)
// CHECK-GNU-NEXT: store double [[COERCE2_IMAG]], ptr [[RETVAL_IMAGP]], align 8
// CHECK-GNU-NEXT: [[TMP3:%.*]] = load [4 x i32], ptr [[RETVAL]], align 8
// CHECK-GNU-NEXT: ret [4 x i32] [[TMP3]]
//

_Complex double checkComplexDoubleOnStack(int x1, _Complex float cf, int x2, _Complex double cd)
{
return testComplexDouble(x2, cf, cd);
Expand Down Expand Up @@ -343,7 +345,7 @@ _Complex double checkComplexDoubleOnStack(int x1, _Complex float cf, int x2, _Co
// CHECK-DEF-NEXT: store double [[AGG_RESULT_REAL]], ptr [[AGG_RESULT_REALP4]], align 8
// CHECK-DEF-NEXT: store double [[AGG_RESULT_IMAG]], ptr [[AGG_RESULT_IMAGP5]], align 8
// CHECK-DEF-NEXT: ret void
//

// CHECK-GNU-LABEL: define dso_local [4 x i32] @checkComplexFloatOnStack
// CHECK-GNU-SAME: ([4 x i32] noundef [[_CD1_COERCE:%.*]], [1 x i64] noundef [[_CF1_COERCE:%.*]], i32 noundef [[Y:%.*]], ptr noundef byval({ float, float }) align 4 [[_CF2:%.*]]) #[[ATTR0]] {
// CHECK-GNU-NEXT: entry:
Expand Down Expand Up @@ -387,7 +389,7 @@ _Complex double checkComplexDoubleOnStack(int x1, _Complex float cf, int x2, _Co
// CHECK-GNU-NEXT: store double [[COERCE1_IMAG]], ptr [[RETVAL_IMAGP]], align 8
// CHECK-GNU-NEXT: [[TMP2:%.*]] = load [4 x i32], ptr [[RETVAL]], align 8
// CHECK-GNU-NEXT: ret [4 x i32] [[TMP2]]
//

_Complex double checkComplexFloatOnStack(_Complex double _cd1, _Complex float _cf1, int y, _Complex float _cf2)
{
return checkComplexDoubleOnStack(y, _cf2, 0, _cd1);
Expand Down
Loading

0 comments on commit 473e188

Please sign in to comment.