* [SPARC] Fix PR target/114416
@ 2024-04-25 10:48 Eric Botcazou
2024-04-25 17:38 ` Eric Botcazou
0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2024-04-25 10:48 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 950 bytes --]
For the 20th anniversary of https://gcc.gnu.org/gcc-3.4/sparc-abi.html, a new
calling convention incompatibility with the vendor compiler (and the ABI) has
been discovered in 64-bit mode, affecting small structures containing arrays
of floating-point components. The decision has been made to fix it on Solaris
only at this point.
Bootstrapped/regtested on SPARC/Solaris 11.4 and SPARC64/Linux by Rainer (many
thanks again) and applied on the mainline.
2024-04-25 Eric Botcazou <ebotcazou@adacore.com>
PR target/114416
* config/sparc/sparc.h (SUN_V9_ABI_COMPATIBILITY): New macro.
* config/sparc/sol2.h (SUN_V9_ABI_COMPATIBILITY): Redefine it.
* config/sparc/sparc.cc (fp_type_for_abi): New predicate.
(traverse_record_type): Use it to spot floating-point types.
(compute_fp_layout): Also deal with array types.
2024-04-25 Eric Botcazou <ebotcazou@adacore.com>
* gcc.target/sparc/small-struct-1.c: New test.
--
Eric Botcazou
[-- Attachment #2: pr114416.diff --]
[-- Type: text/x-patch, Size: 2594 bytes --]
diff --git a/gcc/config/sparc/sol2.h b/gcc/config/sparc/sol2.h
index e849af9038b..552f58b2cc8 100644
--- a/gcc/config/sparc/sol2.h
+++ b/gcc/config/sparc/sol2.h
@@ -456,3 +456,6 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
#undef SPARC_LOW_FE_EXCEPT_VALUES
#define SPARC_LOW_FE_EXCEPT_VALUES 1
+
+#undef SUN_V9_ABI_COMPATIBILITY
+#define SUN_V9_ABI_COMPATIBILITY 1
diff --git a/gcc/config/sparc/sparc.cc b/gcc/config/sparc/sparc.cc
index 30fa4474bbd..8a5f76c8885 100644
--- a/gcc/config/sparc/sparc.cc
+++ b/gcc/config/sparc/sparc.cc
@@ -6782,6 +6782,22 @@ sparc_pass_by_reference (cumulative_args_t, const function_arg_info &arg)
|| GET_MODE_SIZE (mode) > 16);
}
+/* Return true if TYPE is considered as a floating-point type by the ABI. */
+
+static bool
+fp_type_for_abi (const_tree type)
+{
+ /* This is the original GCC implementation. */
+ if (FLOAT_TYPE_P (type) || VECTOR_TYPE_P (type))
+ return true;
+
+ /* This has been introduced in GCC 14 to match the vendor compiler. */
+ if (SUN_V9_ABI_COMPATIBILITY && TREE_CODE (type) == ARRAY_TYPE)
+ return fp_type_for_abi (TREE_TYPE (type));
+
+ return false;
+}
+
/* Traverse the record TYPE recursively and call FUNC on its fields.
NAMED is true if this is for a named parameter. DATA is passed
to FUNC for each field. OFFSET is the starting position and
@@ -6820,8 +6836,7 @@ traverse_record_type (const_tree type, bool named, T *data,
packed);
else
{
- const bool fp_type
- = FLOAT_TYPE_P (field_type) || VECTOR_TYPE_P (field_type);
+ const bool fp_type = fp_type_for_abi (field_type);
Func (field, bitpos, fp_type && named && !packed && TARGET_FPU,
data);
}
@@ -7072,6 +7087,13 @@ compute_fp_layout (const_tree field, int bitpos, assign_data_t *data,
mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field)));
nregs = 2;
}
+ else if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE)
+ {
+ tree elt_type = strip_array_types (TREE_TYPE (field));
+ mode = TYPE_MODE (elt_type);
+ nregs
+ = int_size_in_bytes (TREE_TYPE (field)) / int_size_in_bytes (elt_type);
+ }
else
nregs = 1;
diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h
index fb074808d30..232ecb30ddc 100644
--- a/gcc/config/sparc/sparc.h
+++ b/gcc/config/sparc/sparc.h
@@ -1700,3 +1700,6 @@ extern int sparc_indent_opcode;
#define SPARC_LOW_FE_EXCEPT_VALUES 0
#define TARGET_SUPPORTS_WIDE_INT 1
+
+/* Define this to 1 to accept ABI changes to match the vendor compiler. */
+#define SUN_V9_ABI_COMPATIBILITY 0
[-- Attachment #3: small-struct-1.c --]
[-- Type: text/x-csrc, Size: 640 bytes --]
/* PR target/114416 */
/* Reported by Rainer Orth <ro@gcc.gnu.org> */
/* { dg-do compile } */
/* { dg-options "-O" } */
/* { dg-require-effective-target lp64 } */
struct vec2
{
double x[2];
};
struct vec2x
{
double x;
double y;
};
struct vec2 sum2 (double val)
{
struct vec2 v;
v.x[0] = val;
v.x[1] = val;
return v;
}
struct vec2x sum2x (double val)
{
struct vec2x v;
v.x = val;
v.y = val;
return v;
}
double get2 (struct vec2 v)
{
return v.x[0] + v.x[1];
}
double get2x (struct vec2x v)
{
return v.x + v.y;
}
/* { dg-final { scan-assembler-not "ldx" } } */
/* { dg-final { scan-assembler-not "stx" } } */
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [SPARC] Fix PR target/114416
2024-04-25 10:48 [SPARC] Fix PR target/114416 Eric Botcazou
@ 2024-04-25 17:38 ` Eric Botcazou
0 siblings, 0 replies; 2+ messages in thread
From: Eric Botcazou @ 2024-04-25 17:38 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 439 bytes --]
> For the 20th anniversary of https://gcc.gnu.org/gcc-3.4/sparc-abi.html, a
> new calling convention incompatibility with the vendor compiler (and the
> ABI) has been discovered in 64-bit mode, affecting small structures
> containing arrays of floating-point components. The decision has been made
> to fix it on Solaris only at this point.
Documented by the attached patch, validated with W3C's Validator and applied.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 973 bytes --]
diff --git a/htdocs/gcc-14/changes.html b/htdocs/gcc-14/changes.html
index f0f0efe0..83b1016c 100644
--- a/htdocs/gcc-14/changes.html
+++ b/htdocs/gcc-14/changes.html
@@ -136,7 +136,7 @@ a work-in-progress.</p>
int foo (int n)
{
int res = 0;
- for (int i = 0; i < n; i++)
+ for (int i = 0; i < n; i++)
{
y[i] = x[i] * 2;
res += x[i] + y[i];
@@ -1212,7 +1212,17 @@ __asm (".global __flmap_lock" "\n\t"
<!-- <h3 id="sh">SH</h3> -->
-<!-- <h3 id="sparc">SPARC</h3> -->
+<h3 id="sparc">SPARC</h3>
+
+<ul>
+ <li>
+ The implementation of calling conventions for small structures containing
+ arrays of floating-point components has been changed in 64-bit mode for
+ the Solaris port to match the implementation of the vendor compiler (and
+ the ABI). As a result, the code generated will not be binary compatible
+ with earlier releases in these cases.
+ </li>
+</ul>
<!-- <h3 id="Tile">Tile</h3> -->
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-25 17:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25 10:48 [SPARC] Fix PR target/114416 Eric Botcazou
2024-04-25 17:38 ` Eric Botcazou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).