Hi.
This is a patch for the bug 117923.
I'd like to know if there's a simpler fix for this.
I tried keeping all the fields in the same struct and annotating the
scalar fields as in:
enum GTY((skip)) machine_mode mode;
but it didn't fix the issue.
Any other ideas?
The following test suites passed for this patch:
* The aarch64 tests.
* The aarch64 regression tests.
Here are the test results:
=== gcc Summary ===
# of expected passes 382150
# of unexpected failures 146
# of unexpected successes 16
# of expected failures 1946
# of unresolved testcases 48
# of unsupported tests 5465
/home/antoyo/gcc-build/build/gcc/xgcc version 15.0.0 20241203
(experimental) (GCC)
Same on the master branch:
# Comparing directories
## Dir1=/home/antoyo/tmp/gcc-compare/master/: 2 sum files
## Dir2=/home/antoyo/tmp/gcc-compare/fix-aarch64/: 2 sum files
# Comparing 2 common sum files
## /bin/sh ./contrib/compare_tests /tmp/gxx-sum1.32352 /tmp/gxx-sum2.32352
# No differences found in 2 common sum files
I also ran the jit tests on Aarch64 with another patch and there are
much less failures now.
Thanks for the review.
From 9769e3749cf742b033ad26fd0869d136912d8758 Mon Sep 17 00:00:00 2001
From: Antoni Boucher <boua...@zoho.com>
Date: Wed, 4 Dec 2024 20:59:53 -0500
Subject: [PATCH] aarch64: Fix ICE happening in SET_TYPE_VECTOR_SUBPARTS with
libgccjit
The structure aarch64_simd_type_info was split in 2 because we do not
want to reset the static members of aarch64_simd_type_info to their
default value. We only want the tree types to be GC-ed. This is
necessary for libgccjit which can run multiple times in the same
process. If the static values were GC-ed, the second run would
ICE/segfault because of their invalid value.
The following test suites passed for this patch:
* The aarch64 tests.
* The aarch64 regression tests.
The number of failures of the jit tests on aarch64 lowered from +100 to
~7.
gcc/ChangeLog:
PR target/117923
* config/aarch64/aarch64-builtins.cc: Remove GTY marker on aarch64_simd_types,
aarch64_simd_types_trees (new variable), rename aarch64_simd_types to
aarch64_simd_types_trees.
* config/aarch64/aarch64-builtins.h: Remove GTY marker on aarch64_simd_types,
aarch64_simd_types_trees (new variable).
* config/aarch64/aarch64-sve-builtins-shapes.cc: Rename aarch64_simd_types to
aarch64_simd_types_trees.
* config/aarch64/aarch64-sve-builtins.cc: Rename aarch64_simd_types to
aarch64_simd_types_trees.
---
gcc/config/aarch64/aarch64-builtins.cc | 129 ++++++++++--------
gcc/config/aarch64/aarch64-builtins.h | 29 ++--
.../aarch64/aarch64-sve-builtins-shapes.cc | 4 +-
gcc/config/aarch64/aarch64-sve-builtins.cc | 2 +-
4 files changed, 95 insertions(+), 69 deletions(-)
diff --git a/gcc/config/aarch64/aarch64-builtins.cc b/gcc/config/aarch64/aarch64-builtins.cc
index 22f8216a45b..2990fe79a51 100644
--- a/gcc/config/aarch64/aarch64-builtins.cc
+++ b/gcc/config/aarch64/aarch64-builtins.cc
@@ -982,16 +982,20 @@ const char *aarch64_scalar_builtin_types[] = {
NULL
};
-extern GTY(()) aarch64_simd_type_info aarch64_simd_types[];
+extern const aarch64_simd_type_info aarch64_simd_types[];
+extern GTY(()) aarch64_simd_type_info_trees aarch64_simd_types_trees[];
#undef ENTRY
#define ENTRY(E, M, Q, G) \
- {E, "__" #E, #G "__" #E, NULL_TREE, NULL_TREE, E_##M##mode, qualifier_##Q},
-struct aarch64_simd_type_info aarch64_simd_types [] = {
+ {E, "__" #E, #G "__" #E, E_##M##mode, qualifier_##Q},
+const struct aarch64_simd_type_info aarch64_simd_types [] = {
#include "aarch64-simd-builtin-types.def"
};
#undef ENTRY
+struct aarch64_simd_type_info_trees
+aarch64_simd_types_trees [ARRAY_SIZE (aarch64_simd_types)];
+
static machine_mode aarch64_simd_tuple_modes[ARM_NEON_H_TYPES_LAST][3];
static GTY(()) tree aarch64_simd_tuple_types[ARM_NEON_H_TYPES_LAST][3];
@@ -1132,7 +1136,7 @@ aarch64_lookup_simd_type_in_table (machine_mode mode,
{
if (aarch64_simd_types[i].mode == mode
&& aarch64_simd_types[i].q == q)
- return aarch64_simd_types[i].itype;
+ return aarch64_simd_types_trees[i].itype;
if (aarch64_simd_tuple_types[i][0] != NULL_TREE)
for (int j = 0; j < 3; j++)
if (aarch64_simd_tuple_modes[i][j] == mode
@@ -1179,66 +1183,76 @@ aarch64_init_simd_builtin_types (void)
tree tdecl;
/* Init all the element types built by the front-end. */
- aarch64_simd_types[Int8x8_t].eltype = intQI_type_node;
- aarch64_simd_types[Int8x16_t].eltype = intQI_type_node;
- aarch64_simd_types[Int16x4_t].eltype = intHI_type_node;
- aarch64_simd_types[Int16x8_t].eltype = intHI_type_node;
- aarch64_simd_types[Int32x2_t].eltype = intSI_type_node;
- aarch64_simd_types[Int32x4_t].eltype = intSI_type_node;
- aarch64_simd_types[Int64x1_t].eltype = intDI_type_node;
- aarch64_simd_types[Int64x2_t].eltype = intDI_type_node;
- aarch64_simd_types[Uint8x8_t].eltype = unsigned_intQI_type_node;
- aarch64_simd_types[Uint8x16_t].eltype = unsigned_intQI_type_node;
- aarch64_simd_types[Uint16x4_t].eltype = unsigned_intHI_type_node;
- aarch64_simd_types[Uint16x8_t].eltype = unsigned_intHI_type_node;
- aarch64_simd_types[Uint32x2_t].eltype = unsigned_intSI_type_node;
- aarch64_simd_types[Uint32x4_t].eltype = unsigned_intSI_type_node;
- aarch64_simd_types[Uint64x1_t].eltype = unsigned_intDI_type_node;
- aarch64_simd_types[Uint64x2_t].eltype = unsigned_intDI_type_node;
+ aarch64_simd_types_trees[Int8x8_t].eltype = intQI_type_node;
+ aarch64_simd_types_trees[Int8x16_t].eltype = intQI_type_node;
+ aarch64_simd_types_trees[Int16x4_t].eltype = intHI_type_node;
+ aarch64_simd_types_trees[Int16x8_t].eltype = intHI_type_node;
+ aarch64_simd_types_trees[Int32x2_t].eltype = intSI_type_node;
+ aarch64_simd_types_trees[Int32x4_t].eltype = intSI_type_node;
+ aarch64_simd_types_trees[Int64x1_t].eltype = intDI_type_node;
+ aarch64_simd_types_trees[Int64x2_t].eltype = intDI_type_node;
+ aarch64_simd_types_trees[Uint8x8_t].eltype = unsigned_intQI_type_node;
+ aarch64_simd_types_trees[Uint8x16_t].eltype = unsigned_intQI_type_node;
+ aarch64_simd_types_trees[Uint16x4_t].eltype = unsigned_intHI_type_node;
+ aarch64_simd_types_trees[Uint16x8_t].eltype = unsigned_intHI_type_node;
+ aarch64_simd_types_trees[Uint32x2_t].eltype = unsigned_intSI_type_node;
+ aarch64_simd_types_trees[Uint32x4_t].eltype = unsigned_intSI_type_node;
+ aarch64_simd_types_trees[Uint64x1_t].eltype = unsigned_intDI_type_node;
+ aarch64_simd_types_trees[Uint64x2_t].eltype = unsigned_intDI_type_node;
/* Poly types are a world of their own. */
- aarch64_simd_types[Poly8_t].eltype = aarch64_simd_types[Poly8_t].itype =
- build_distinct_type_copy (unsigned_intQI_type_node);
+ aarch64_simd_types_trees[Poly8_t].eltype
+ = aarch64_simd_types_trees[Poly8_t].itype
+ = build_distinct_type_copy (unsigned_intQI_type_node);
/* Prevent front-ends from transforming Poly8_t arrays into string
literals. */
- TYPE_STRING_FLAG (aarch64_simd_types[Poly8_t].eltype) = false;
-
- aarch64_simd_types[Poly16_t].eltype = aarch64_simd_types[Poly16_t].itype =
- build_distinct_type_copy (unsigned_intHI_type_node);
- aarch64_simd_types[Poly64_t].eltype = aarch64_simd_types[Poly64_t].itype =
- build_distinct_type_copy (unsigned_intDI_type_node);
- aarch64_simd_types[Poly128_t].eltype = aarch64_simd_types[Poly128_t].itype =
- build_distinct_type_copy (unsigned_intTI_type_node);
+ TYPE_STRING_FLAG (aarch64_simd_types_trees[Poly8_t].eltype) = false;
+
+ aarch64_simd_types_trees[Poly16_t].eltype
+ = aarch64_simd_types_trees[Poly16_t].itype
+ = build_distinct_type_copy (unsigned_intHI_type_node);
+ aarch64_simd_types_trees[Poly64_t].eltype
+ = aarch64_simd_types_trees[Poly64_t].itype
+ = build_distinct_type_copy (unsigned_intDI_type_node);
+ aarch64_simd_types_trees[Poly128_t].eltype
+ = aarch64_simd_types_trees[Poly128_t].itype
+ = build_distinct_type_copy (unsigned_intTI_type_node);
/* Init poly vector element types with scalar poly types. */
- aarch64_simd_types[Poly8x8_t].eltype = aarch64_simd_types[Poly8_t].itype;
- aarch64_simd_types[Poly8x16_t].eltype = aarch64_simd_types[Poly8_t].itype;
- aarch64_simd_types[Poly16x4_t].eltype = aarch64_simd_types[Poly16_t].itype;
- aarch64_simd_types[Poly16x8_t].eltype = aarch64_simd_types[Poly16_t].itype;
- aarch64_simd_types[Poly64x1_t].eltype = aarch64_simd_types[Poly64_t].itype;
- aarch64_simd_types[Poly64x2_t].eltype = aarch64_simd_types[Poly64_t].itype;
+ aarch64_simd_types_trees[Poly8x8_t].eltype
+ = aarch64_simd_types_trees[Poly8_t].itype;
+ aarch64_simd_types_trees[Poly8x16_t].eltype
+ = aarch64_simd_types_trees[Poly8_t].itype;
+ aarch64_simd_types_trees[Poly16x4_t].eltype
+ = aarch64_simd_types_trees[Poly16_t].itype;
+ aarch64_simd_types_trees[Poly16x8_t].eltype
+ = aarch64_simd_types_trees[Poly16_t].itype;
+ aarch64_simd_types_trees[Poly64x1_t].eltype
+ = aarch64_simd_types_trees[Poly64_t].itype;
+ aarch64_simd_types_trees[Poly64x2_t].eltype
+ = aarch64_simd_types_trees[Poly64_t].itype;
/* Continue with standard types. */
- aarch64_simd_types[Float16x4_t].eltype = aarch64_fp16_type_node;
- aarch64_simd_types[Float16x8_t].eltype = aarch64_fp16_type_node;
- aarch64_simd_types[Float32x2_t].eltype = float_type_node;
- aarch64_simd_types[Float32x4_t].eltype = float_type_node;
- aarch64_simd_types[Float64x1_t].eltype = double_type_node;
- aarch64_simd_types[Float64x2_t].eltype = double_type_node;
+ aarch64_simd_types_trees[Float16x4_t].eltype = aarch64_fp16_type_node;
+ aarch64_simd_types_trees[Float16x8_t].eltype = aarch64_fp16_type_node;
+ aarch64_simd_types_trees[Float32x2_t].eltype = float_type_node;
+ aarch64_simd_types_trees[Float32x4_t].eltype = float_type_node;
+ aarch64_simd_types_trees[Float64x1_t].eltype = double_type_node;
+ aarch64_simd_types_trees[Float64x2_t].eltype = double_type_node;
/* Init Bfloat vector types with underlying __bf16 type. */
- aarch64_simd_types[Bfloat16x4_t].eltype = bfloat16_type_node;
- aarch64_simd_types[Bfloat16x8_t].eltype = bfloat16_type_node;
+ aarch64_simd_types_trees[Bfloat16x4_t].eltype = bfloat16_type_node;
+ aarch64_simd_types_trees[Bfloat16x8_t].eltype = bfloat16_type_node;
/* Init FP8 element types. */
- aarch64_simd_types[Mfloat8x8_t].eltype = aarch64_mfp8_type_node;
- aarch64_simd_types[Mfloat8x16_t].eltype = aarch64_mfp8_type_node;
+ aarch64_simd_types_trees[Mfloat8x8_t].eltype = aarch64_mfp8_type_node;
+ aarch64_simd_types_trees[Mfloat8x16_t].eltype = aarch64_mfp8_type_node;
for (i = 0; i < nelts; i++)
{
- tree eltype = aarch64_simd_types[i].eltype;
+ tree eltype = aarch64_simd_types_trees[i].eltype;
machine_mode mode = aarch64_simd_types[i].mode;
- if (aarch64_simd_types[i].itype == NULL)
+ if (aarch64_simd_types_trees[i].itype == NULL)
{
tree type = build_vector_type (eltype, GET_MODE_NUNITS (mode));
type = build_distinct_type_copy (type);
@@ -1249,12 +1263,12 @@ aarch64_init_simd_builtin_types (void)
TYPE_ATTRIBUTES (type)
= tree_cons (get_identifier ("Advanced SIMD type"), value,
TYPE_ATTRIBUTES (type));
- aarch64_simd_types[i].itype = type;
+ aarch64_simd_types_trees[i].itype = type;
}
tdecl = add_builtin_type (aarch64_simd_types[i].name,
- aarch64_simd_types[i].itype);
- TYPE_NAME (aarch64_simd_types[i].itype) = tdecl;
+ aarch64_simd_types_trees[i].itype);
+ TYPE_NAME (aarch64_simd_types_trees[i].itype) = tdecl;
}
#define AARCH64_BUILD_SIGNED_TYPE(mode) \
@@ -1736,7 +1750,8 @@ aarch64_get_pragma_builtin (int code)
static void
register_tuple_type (unsigned int num_vectors, unsigned int type_index)
{
- aarch64_simd_type_info *type = &aarch64_simd_types[type_index];
+ const aarch64_simd_type_info *type = &aarch64_simd_types[type_index];
+ aarch64_simd_type_info_trees *trees = &aarch64_simd_types_trees[type_index];
/* Synthesize the name of the user-visible vector tuple type. */
const char *vector_type_name = type->name;
@@ -1746,7 +1761,7 @@ register_tuple_type (unsigned int num_vectors, unsigned int type_index)
num_vectors);
tuple_type_name[0] = TOLOWER (tuple_type_name[0]);
- tree vector_type = type->itype;
+ tree vector_type = trees->itype;
tree array_type = build_array_type_nelts (vector_type, num_vectors);
if (type->mode == DImode)
{
@@ -4096,8 +4111,8 @@ aarch64_general_gimple_fold_builtin (unsigned int fcode, gcall *stmt,
{
enum aarch64_simd_type mem_type
= get_mem_type_for_load_store(fcode);
- aarch64_simd_type_info simd_type
- = aarch64_simd_types[mem_type];
+ aarch64_simd_type_info_trees simd_type
+ = aarch64_simd_types_trees[mem_type];
tree elt_ptr_type = build_pointer_type_for_mode (simd_type.eltype,
VOIDmode, true);
tree zero = build_zero_cst (elt_ptr_type);
@@ -4122,8 +4137,8 @@ aarch64_general_gimple_fold_builtin (unsigned int fcode, gcall *stmt,
{
enum aarch64_simd_type mem_type
= get_mem_type_for_load_store(fcode);
- aarch64_simd_type_info simd_type
- = aarch64_simd_types[mem_type];
+ aarch64_simd_type_info_trees simd_type
+ = aarch64_simd_types_trees[mem_type];
tree elt_ptr_type = build_pointer_type_for_mode (simd_type.eltype,
VOIDmode, true);
tree zero = build_zero_cst (elt_ptr_type);
diff --git a/gcc/config/aarch64/aarch64-builtins.h b/gcc/config/aarch64/aarch64-builtins.h
index 00db7a74885..f4d54de5f7b 100644
--- a/gcc/config/aarch64/aarch64-builtins.h
+++ b/gcc/config/aarch64/aarch64-builtins.h
@@ -66,7 +66,7 @@ enum aarch64_simd_type
};
#undef ENTRY
-struct GTY(()) aarch64_simd_type_info
+struct aarch64_simd_type_info
{
enum aarch64_simd_type type;
@@ -83,12 +83,6 @@ struct GTY(()) aarch64_simd_type_info
will get default mangled names. */
const char *mangle;
- /* Internal type. */
- tree itype;
-
- /* Element type. */
- tree eltype;
-
/* Machine mode the internal type maps to. */
enum machine_mode mode;
@@ -96,6 +90,23 @@ struct GTY(()) aarch64_simd_type_info
enum aarch64_type_qualifiers q;
};
-extern aarch64_simd_type_info aarch64_simd_types[];
+/* This is in a different structure than aarch64_simd_type_info because we do
+ not want to reset the static members of aarch64_simd_type_info to their
+ default value. We only want the tree types to be GC-ed.
+ This is necessary for libgccjit which can run multiple times in the same
+ process. If the static values were GC-ed, the second run would ICE/segfault
+ because of their invalid value.
+ */
+struct GTY(()) aarch64_simd_type_info_trees
+{
+ /* Internal type. */
+ tree itype;
+
+ /* Element type. */
+ tree eltype;
+};
+
+extern const aarch64_simd_type_info aarch64_simd_types[];
+extern aarch64_simd_type_info_trees aarch64_simd_types_trees[];
-#endif
\ No newline at end of file
+#endif
diff --git a/gcc/config/aarch64/aarch64-sve-builtins-shapes.cc b/gcc/config/aarch64/aarch64-sve-builtins-shapes.cc
index cf3ddab09b6..bfee2a7870e 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins-shapes.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins-shapes.cc
@@ -272,14 +272,14 @@ parse_type (const function_instance &instance, const char *&format)
{
type_suffix_index suffix = parse_element_type (instance, format);
int neon_index = type_suffixes[suffix].neon64_type;
- return aarch64_simd_types[neon_index].itype;
+ return aarch64_simd_types_trees[neon_index].itype;
}
if (ch == 'Q')
{
type_suffix_index suffix = parse_element_type (instance, format);
int neon_index = type_suffixes[suffix].neon128_type;
- return aarch64_simd_types[neon_index].itype;
+ return aarch64_simd_types_trees[neon_index].itype;
}
gcc_unreachable ();
diff --git a/gcc/config/aarch64/aarch64-sve-builtins.cc b/gcc/config/aarch64/aarch64-sve-builtins.cc
index 8e94a2d2cfe..79159df8ccd 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins.cc
@@ -2166,7 +2166,7 @@ function_resolver::infer_neon128_vector_type (unsigned int argno)
int neon_index = type_suffixes[suffix_i].neon128_type;
if (neon_index != ARM_NEON_H_TYPES_LAST)
{
- tree type = aarch64_simd_types[neon_index].itype;
+ tree type = aarch64_simd_types_trees[neon_index].itype;
if (type && matches_type_p (type, actual))
return type_suffix_index (suffix_i);
}
--
2.47.1