On 11/19/24 10:29 AM, Andrew Carlotti wrote:
On Sun, Oct 27, 2024 at 04:00:43PM +0000, Yangyu Chen wrote:
Following the implementation of commit b8ce8129a5 ("Redirect call
within specific target attribute among MV clones (PR ipa/82625)"),
we can now optimize calls by invoking a versioned function callee
from a caller that shares the same target attribute. However, on
targets that define TARGET_HAS_FMV_TARGET_ATTRIBUTE to zero, meaning
they use the "target_versions" attribute instead of "target", this
optimization is not feasible. Currently, the only target affected
by this limitation is AArch64.
The existing optimization can pick the wrong version in some cases, and fixing
this properly requires better comparisons than just a simple string comparison.
I'd prefer to just disable this optimization for aarch64 and riscv for now (and
backport that fix to gcc-14), and add the necessary target hooks to be able to
implement it properly at a later date. (The existing bug applies if you
specify both target and target_version/target_clones attributes on the same
function, which is an unlikely combination but one that we deliberately chose
to support in aarch64).
To give a specific example, suppose we have target features featv3, featv2 and
featv1, with featv3 implying featv2 implying featv1. Suppose we have the
following function versions:
Caller: featv2, featv1, default
Callee: featv3, featv2, featv1, default
In the featv1 and default versions of the caller, we know that we would always
select the corresponding version of the callee function, so the redirection is
valid there.
However, in the featv2 version of the caller, we don't know whether we would
select the featv2 or the featv3 versions of the callee at runtime, so we cannot
eliminate the runtime indirection.
Conservatively we could direct to featv2, ie a direct match. Directing
to featv3 would have to be driven by a target hook or some mechanism for
generically handling sub/super sets.
Jeff