diff mbox series

Fix MV clones can not redirect to specific target on some targets

Message ID tencent_3797B8AB317A21E78D6E7C6C8266DA138E08@qq.com
State New
Headers show
Series Fix MV clones can not redirect to specific target on some targets | expand

Commit Message

Yangyu Chen Oct. 27, 2024, 3:12 p.m. UTC
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.

This commit resolves the issue by not directly using "target" with
lookup_attribute. Instead, it checks the TARGET_HAS_FMV_TARGET_ATTRIBUTE
macro to decide between using the "target" or "target_version"
attribute.

Fixes: 79891c4cb5 ("Add support for target_version attribute")

gcc/ChangeLog:

	* multiple_target.cc (redirect_to_specific_clone): Fix the redirection
	does not work on target without TARGET_HAS_FMV_TARGET_ATTRIBUTE.
---
 gcc/multiple_target.cc | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc
index d2c9671fc1b..a1c18f4a3a7 100644
--- a/gcc/multiple_target.cc
+++ b/gcc/multiple_target.cc
@@ -446,8 +446,10 @@  redirect_to_specific_clone (cgraph_node *node)
   cgraph_function_version_info *fv = node->function_version ();
   if (fv == NULL)
     return;
+  const char *fmv_attr = (TARGET_HAS_FMV_TARGET_ATTRIBUTE
+			  ? "target" : "target_version");
 
-  tree attr_target = lookup_attribute ("target", DECL_ATTRIBUTES (node->decl));
+  tree attr_target = lookup_attribute (fmv_attr, DECL_ATTRIBUTES (node->decl));
   if (attr_target == NULL_TREE)
     return;
 
@@ -458,7 +460,7 @@  redirect_to_specific_clone (cgraph_node *node)
       if (!fv2)
 	continue;
 
-      tree attr_target2 = lookup_attribute ("target",
+      tree attr_target2 = lookup_attribute (fmv_attr,
 					    DECL_ATTRIBUTES (e->callee->decl));
 
       /* Function is not calling proper target clone.  */
@@ -472,7 +474,7 @@  redirect_to_specific_clone (cgraph_node *node)
 	  for (; fv2 != NULL; fv2 = fv2->next)
 	    {
 	      cgraph_node *callee = fv2->this_node;
-	      attr_target2 = lookup_attribute ("target",
+	      attr_target2 = lookup_attribute (fmv_attr,
 					       DECL_ATTRIBUTES (callee->decl));
 	      if (attr_target2 != NULL_TREE
 		  && attribute_value_equal (attr_target, attr_target2))