Skip to content

Commit 045e79e

Browse files
committed
[VE] Extend integer arguments and return values smaller than 64 bits
In order to follow NEC Aurora SX VE ABI correctly, change to sign/zero extend integer arguments and return values smaller than 64 bits in clang. Also update regression test. Reviewed By: simoll Differential Revision: https://reviews.llvm.org/D85071
1 parent 3b92db4 commit 045e79e

File tree

2 files changed

+95
-10
lines changed

2 files changed

+95
-10
lines changed

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10743,21 +10743,24 @@ class VEABIInfo : public DefaultABIInfo {
1074310743
} // end anonymous namespace
1074410744

1074510745
ABIArgInfo VEABIInfo::classifyReturnType(QualType Ty) const {
10746-
if (Ty->isAnyComplexType()) {
10746+
if (Ty->isAnyComplexType())
1074710747
return ABIArgInfo::getDirect();
10748-
}
10748+
uint64_t Size = getContext().getTypeSize(Ty);
10749+
if (Size < 64 && Ty->isIntegerType())
10750+
return ABIArgInfo::getExtend(Ty);
1074910751
return DefaultABIInfo::classifyReturnType(Ty);
1075010752
}
1075110753

1075210754
ABIArgInfo VEABIInfo::classifyArgumentType(QualType Ty) const {
10753-
if (Ty->isAnyComplexType()) {
10755+
if (Ty->isAnyComplexType())
1075410756
return ABIArgInfo::getDirect();
10755-
}
10757+
uint64_t Size = getContext().getTypeSize(Ty);
10758+
if (Size < 64 && Ty->isIntegerType())
10759+
return ABIArgInfo::getExtend(Ty);
1075610760
return DefaultABIInfo::classifyArgumentType(Ty);
1075710761
}
1075810762

1075910763
void VEABIInfo::computeInfo(CGFunctionInfo &FI) const {
10760-
1076110764
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
1076210765
for (auto &Arg : FI.arguments())
1076310766
Arg.info = classifyArgumentType(Arg.type);

clang/test/CodeGen/ve-abi.c

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,96 @@
1+
/// Check that ABI is correctly implemented.
2+
///
3+
/// 1. Check that all integer arguments and return values less than 64 bits
4+
/// are sign/zero extended.
5+
/// 2. Check that all complex arguments and return values are placed in
6+
/// registers if it is possible. Not treat it as aggregate.
7+
/// 3. Check that a function declared without argument type declarations is
8+
/// treated as VARARGS (in order to place arguments in both registers and
9+
/// memory locations in the back end)
10+
111
// RUN: %clang_cc1 -triple ve-linux-gnu -emit-llvm %s -o - | FileCheck %s
212

3-
// CHECK-LABEL: define { float, float } @p(float %a.coerce0, float %a.coerce1, float %b.coerce0, float %b.coerce1) #0 {
4-
float __complex__ p(float __complex__ a, float __complex__ b) {
13+
// CHECK-LABEL: define signext i8 @fun_si8(i8 signext %a, i8 signext %b) #0 {
14+
char fun_si8(char a, char b) {
15+
return a;
16+
}
17+
18+
// CHECK-LABEL: define zeroext i8 @fun_zi8(i8 zeroext %a, i8 zeroext %b) #0 {
19+
unsigned char fun_zi8(unsigned char a, unsigned char b) {
20+
return a;
21+
}
22+
23+
// CHECK-LABEL: define signext i16 @fun_si16(i16 signext %a, i16 signext %b) #0 {
24+
short fun_si16(short a, short b) {
25+
return a;
26+
}
27+
28+
// CHECK-LABEL: define zeroext i16 @fun_zi16(i16 zeroext %a, i16 zeroext %b) #0 {
29+
unsigned short fun_zi16(unsigned short a, unsigned short b) {
30+
return a;
31+
}
32+
33+
// CHECK-LABEL: define signext i32 @fun_si32(i32 signext %a, i32 signext %b) #0 {
34+
int fun_si32(int a, int b) {
35+
return a;
36+
}
37+
38+
// CHECK-LABEL: define zeroext i32 @fun_zi32(i32 zeroext %a, i32 zeroext %b) #0 {
39+
unsigned int fun_zi32(unsigned int a, unsigned int b) {
40+
return a;
41+
}
42+
43+
// CHECK-LABEL: define i64 @fun_si64(i64 %a, i64 %b) #0 {
44+
long fun_si64(long a, long b) {
45+
return a;
46+
}
47+
48+
// CHECK-LABEL: define i64 @fun_zi64(i64 %a, i64 %b) #0 {
49+
unsigned long fun_zi64(unsigned long a, unsigned long b) {
50+
return a;
51+
}
52+
53+
// CHECK-LABEL: define i128 @fun_si128(i128 %a, i128 %b) #0 {
54+
__int128 fun_si128(__int128 a, __int128 b) {
55+
}
56+
57+
// CHECK-LABEL: define i128 @fun_zi128(i128 %a, i128 %b) #0 {
58+
unsigned __int128 fun_zi128(unsigned __int128 a, unsigned __int128 b) {
59+
return a;
60+
}
61+
62+
// CHECK-LABEL: define float @fun_float(float %a, float %b) #0 {
63+
float fun_float(float a, float b) {
64+
return a;
65+
}
66+
67+
// CHECK-LABEL: define double @fun_double(double %a, double %b) #0 {
68+
double fun_double(double a, double b) {
69+
return a;
70+
}
71+
72+
// CHECK-LABEL: define fp128 @fun_quad(fp128 %a, fp128 %b) #0 {
73+
long double fun_quad(long double a, long double b) {
74+
return a;
75+
}
76+
77+
// CHECK-LABEL: define { float, float } @fun_fcomplex(float %a.coerce0, float %a.coerce1, float %b.coerce0, float %b.coerce1) #0 {
78+
float __complex__ fun_fcomplex(float __complex__ a, float __complex__ b) {
79+
return a;
80+
}
81+
82+
// CHECK-LABEL: define { double, double } @fun_dcomplex(double %a.coerce0, double %a.coerce1, double %b.coerce0, double %b.coerce1) #0 {
83+
double __complex__ fun_dcomplex(double __complex__ a, double __complex__ b) {
84+
return a;
585
}
686

7-
// CHECK-LABEL: define { double, double } @q(double %a.coerce0, double %a.coerce1, double %b.coerce0, double %b.coerce1) #0 {
8-
double __complex__ q(double __complex__ a, double __complex__ b) {
87+
// CHECK-LABEL: define { fp128, fp128 } @fun_qcomplex(fp128 %a.coerce0, fp128 %a.coerce1, fp128 %b.coerce0, fp128 %b.coerce1) #0 {
88+
long double __complex__ fun_qcomplex(long double __complex__ a, long double __complex__ b) {
89+
return a;
990
}
1091

92+
extern int hoge();
1193
void func() {
12-
// CHECK-LABEL: %call = call i32 (i32, i32, i32, i32, i32, i32, i32, ...) bitcast (i32 (...)* @hoge to i32 (i32, i32, i32, i32, i32, i32, i32, ...)*)(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7)
94+
// CHECK: %call = call signext i32 (i32, i32, i32, i32, i32, i32, i32, ...) bitcast (i32 (...)* @hoge to i32 (i32, i32, i32, i32, i32, i32, i32, ...)*)(i32 signext 1, i32 signext 2, i32 signext 3, i32 signext 4, i32 signext 5, i32 signext 6, i32 signext 7)
1395
hoge(1, 2, 3, 4, 5, 6, 7);
1496
}

0 commit comments

Comments
 (0)