From: Alex Coplan <alex.coplan@arm.com>
To: gcc-patches@gcc.gnu.org
Cc: Richard Earnshaw <richard.earnshaw@arm.com>,
Richard Sandiford <richard.sandiford@arm.com>,
Kyrylo Tkachov <kyrylo.tkachov@arm.com>,
Richard Biener <richard.guenther@gmail.com>
Subject: [PATCH v2] aarch64: Fix SVE ACLE builtins with LTO [PR99216]
Date: Tue, 9 Mar 2021 15:41:00 +0000 [thread overview]
Message-ID: <20210309154058.5u6cvoo52yrijpue@arm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1821 bytes --]
Hi all,
Here is a v2 patch which provides a more obviously fake answer to
TARGET_BUILTIN_DECL: this can hopefully go in for GCC 11. For GCC 12, it
seems that we should consider removing the target hook.
Original patch:
https://gcc.gnu.org/pipermail/gcc-patches/2021-March/566405.html
---
As discussed in the PR, we currently have two different numbering
schemes for SVE builtins: one for C, and one for C++. This is
problematic for LTO, where we end up getting confused about which
intrinsic we're talking about. This patch inserts placeholders into the
registered_functions vector to ensure that there is a consistent
numbering scheme for both C and C++.
This patch uses integer_zero_node as a placeholder node instead of
building a function decl. This is safe because the node is only returned
by the TARGET_BUILTIN_DECL hook, which (on AArch64) is only used for
validation when builtin decls are streamed into lto1.
Bootstrapped and regtested on aarch64-linux-gnu, OK for trunk?
Thanks,
Alex
gcc/ChangeLog:
PR target/99216
* config/aarch64/aarch64-sve-builtins.cc
(function_builder::add_function): Add placeholder_p argument, use
placeholder decls if this is set.
(function_builder::add_unique_function): Instead of conditionally adding
direct overloads, unconditionally add either a direct overload or a
placeholder.
(function_builder::add_overloaded_function): Set placeholder_p if we're
using C++ overloads. Use the obstack for string storage instead
of relying on the tree nodes.
(function_builder::add_overloaded_functions): Don't return early for
m_direct_overloads: we need to add placeholders.
* config/aarch64/aarch64-sve-builtins.h
(function_builder::add_function): Add placeholder_p argument.
gcc/testsuite/ChangeLog:
PR target/99216
* g++.target/aarch64/sve/pr99216.C: New test.
[-- Attachment #2: patch_v2.txt --]
[-- Type: text/plain, Size: 5686 bytes --]
diff --git a/gcc/config/aarch64/aarch64-sve-builtins.cc b/gcc/config/aarch64/aarch64-sve-builtins.cc
index 25612d2ea52..f44f81f1375 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins.cc
@@ -999,12 +999,29 @@ registered_function &
function_builder::add_function (const function_instance &instance,
const char *name, tree fntype, tree attrs,
uint64_t required_extensions,
- bool overloaded_p)
+ bool overloaded_p,
+ bool placeholder_p)
{
unsigned int code = vec_safe_length (registered_functions);
code = (code << AARCH64_BUILTIN_SHIFT) | AARCH64_BUILTIN_SVE;
- tree decl = simulate_builtin_function_decl (input_location, name, fntype,
- code, NULL, attrs);
+
+ /* We need to be able to generate placeholders to enusre that we have a
+ consistent numbering scheme for function codes between the C and C++
+ frontends, so that everything ties up in LTO.
+
+ Currently, tree-streamer-in.c:unpack_ts_function_decl_value_fields
+ validates that tree nodes returned by TARGET_BUILTIN_DECL are non-NULL and
+ some node other than error_mark_node. This is a holdover from when builtin
+ decls were streamed by code rather than by value.
+
+ Ultimately, we should be able to remove this validation of BUILT_IN_MD
+ nodes and remove the target hook. For now, however, we need to appease the
+ validation and return a non-NULL, non-error_mark_node node, so we
+ arbitrarily choose integer_zero_node. */
+ tree decl = placeholder_p
+ ? integer_zero_node
+ : simulate_builtin_function_decl (input_location, name, fntype,
+ code, NULL, attrs);
registered_function &rfn = *ggc_alloc <registered_function> ();
rfn.instance = instance;
@@ -1036,7 +1053,7 @@ function_builder::add_unique_function (const function_instance &instance,
argument_types.address ());
tree attrs = get_attributes (instance);
registered_function &rfn = add_function (instance, name, fntype, attrs,
- required_extensions, false);
+ required_extensions, false, false);
/* Enter the function into the hash table. */
hashval_t hash = instance.hash ();
@@ -1047,16 +1064,14 @@ function_builder::add_unique_function (const function_instance &instance,
/* Also add the function under its overloaded alias, if we want
a separate decl for each instance of an overloaded function. */
- if (m_direct_overloads || force_direct_overloads)
+ char *overload_name = get_name (instance, true);
+ if (strcmp (name, overload_name) != 0)
{
- char *overload_name = get_name (instance, true);
- if (strcmp (name, overload_name) != 0)
- {
- /* Attribute lists shouldn't be shared. */
- tree attrs = get_attributes (instance);
- add_function (instance, overload_name, fntype, attrs,
- required_extensions, false);
- }
+ /* Attribute lists shouldn't be shared. */
+ tree attrs = get_attributes (instance);
+ bool placeholder_p = !(m_direct_overloads || force_direct_overloads);
+ add_function (instance, overload_name, fntype, attrs,
+ required_extensions, false, placeholder_p);
}
obstack_free (&m_string_obstack, name);
@@ -1077,18 +1092,19 @@ function_builder::add_overloaded_function (const function_instance &instance,
{
char *name = get_name (instance, true);
if (registered_function **map_value = m_overload_names.get (name))
- gcc_assert ((*map_value)->instance == instance
- && ((*map_value)->required_extensions
- & ~required_extensions) == 0);
+ {
+ gcc_assert ((*map_value)->instance == instance
+ && ((*map_value)->required_extensions
+ & ~required_extensions) == 0);
+ obstack_free (&m_string_obstack, name);
+ }
else
{
registered_function &rfn
= add_function (instance, name, m_overload_type, NULL_TREE,
- required_extensions, true);
- const char *permanent_name = IDENTIFIER_POINTER (DECL_NAME (rfn.decl));
- m_overload_names.put (permanent_name, &rfn);
+ required_extensions, true, m_direct_overloads);
+ m_overload_names.put (name, &rfn);
}
- obstack_free (&m_string_obstack, name);
}
/* If we are using manual overload resolution, add one function decl
@@ -1098,9 +1114,6 @@ void
function_builder::add_overloaded_functions (const function_group_info &group,
mode_suffix_index mode)
{
- if (m_direct_overloads)
- return;
-
unsigned int explicit_type0 = (*group.shape)->explicit_type_suffix_p (0);
unsigned int explicit_type1 = (*group.shape)->explicit_type_suffix_p (1);
for (unsigned int pi = 0; group.preds[pi] != NUM_PREDS; ++pi)
diff --git a/gcc/config/aarch64/aarch64-sve-builtins.h b/gcc/config/aarch64/aarch64-sve-builtins.h
index 620e18841b2..b701f90ac1a 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins.h
+++ b/gcc/config/aarch64/aarch64-sve-builtins.h
@@ -337,7 +337,8 @@ private:
tree get_attributes (const function_instance &);
registered_function &add_function (const function_instance &,
- const char *, tree, tree, uint64_t, bool);
+ const char *, tree, tree,
+ uint64_t, bool, bool);
/* The function type to use for functions that are resolved by
function_resolver. */
diff --git a/gcc/testsuite/g++.target/aarch64/sve/pr99216.C b/gcc/testsuite/g++.target/aarch64/sve/pr99216.C
new file mode 100644
index 00000000000..61a58a7fcf4
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/pr99216.C
@@ -0,0 +1,5 @@
+/* { dg-do link { target aarch64_asm_sve_ok } } */
+/* { dg-additional-options "-flto" } */
+#include <arm_sve.h>
+bool a;
+int main() { a = svaddv(svptrue_b8(), svdup_s8(0)); }
next reply other threads:[~2021-03-09 15:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-09 15:41 Alex Coplan [this message]
2021-03-23 11:52 ` Alex Coplan
2021-03-26 16:43 ` Richard Sandiford
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210309154058.5u6cvoo52yrijpue@arm.com \
--to=alex.coplan@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=kyrylo.tkachov@arm.com \
--cc=richard.earnshaw@arm.com \
--cc=richard.guenther@gmail.com \
--cc=richard.sandiford@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).