From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1698) id 927503851C03; Mon, 29 Jun 2020 19:16:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 927503851C03 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1593458177; bh=k0ouFuPFeqZs4QsQ+bSVzG7jYtf2KxiOcz5ETQflzT8=; h=From:To:Subject:Date:From; b=BBtoBQSWIYYzIcjcyMFL4QolqWtaHroeoQeNRNc+Uysd5rnrpNrt8VI+tb9hgis90 qplhhH2Yq7DnTDtX5DqiMS9JXp7JA6Wo76e9flEgPnyCe5SiKY48PQMUSJaW6HFjLm mCvgS0R8IBheioFnhRqB5A8O4NXaNmNDQMCwgpYA= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Iain D Sandoe To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/c++-coroutines] Fix target clone indirection elimination X-Act-Checkin: gcc X-Git-Author: Yichao Yu X-Git-Refname: refs/heads/devel/c++-coroutines X-Git-Oldrev: 67161d24f45601e43abea98f2c3d7d7a462b6eab X-Git-Newrev: 00e90d3d4cb51fd0fae7b2dbd4bab1db26d6676e Message-Id: <20200629191617.927503851C03@sourceware.org> Date: Mon, 29 Jun 2020 19:16:17 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jun 2020 19:16:17 -0000 https://gcc.gnu.org/g:00e90d3d4cb51fd0fae7b2dbd4bab1db26d6676e commit 00e90d3d4cb51fd0fae7b2dbd4bab1db26d6676e Author: Yichao Yu Date: Fri Jun 26 15:46:15 2020 -0600 Fix target clone indirection elimination The current logic seems to be comparing the whole attribute tree between the callee and caller (or at least the tree starting from the target attribute). This is unnecessary and causes strange dependency of the indirection elimination on unrelated properties like `noinline`(PR95780) and `visibility`(PR95778). This changes the comparison to be only on the `target` attribute which should be the intent of the code. gcc * multiple_target.c (redirect_to_specific_clone): Fix tests to check individual attribute rather than an attribute list. gcc/testsuite * gcc.target/i386/pr95778-1.c: New test. * gcc.target/i386/pr95778-2.c: New test. Diff: --- gcc/multiple_target.c | 6 ++++-- gcc/testsuite/gcc.target/i386/pr95778-1.c | 21 +++++++++++++++++++++ gcc/testsuite/gcc.target/i386/pr95778-2.c | 21 +++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/gcc/multiple_target.c b/gcc/multiple_target.c index c1cfe8ff978..b15d004fa4e 100644 --- a/gcc/multiple_target.c +++ b/gcc/multiple_target.c @@ -483,7 +483,8 @@ redirect_to_specific_clone (cgraph_node *node) DECL_ATTRIBUTES (e->callee->decl)); /* Function is not calling proper target clone. */ - if (!attribute_list_equal (attr_target, attr_target2)) + if (attr_target2 == NULL_TREE + || !attribute_value_equal (attr_target, attr_target2)) { while (fv2->prev != NULL) fv2 = fv2->prev; @@ -494,7 +495,8 @@ redirect_to_specific_clone (cgraph_node *node) cgraph_node *callee = fv2->this_node; attr_target2 = lookup_attribute ("target", DECL_ATTRIBUTES (callee->decl)); - if (attribute_list_equal (attr_target, attr_target2)) + if (attr_target2 != NULL_TREE + && attribute_value_equal (attr_target, attr_target2)) { e->redirect_callee (callee); cgraph_edge::redirect_call_stmt_to_callee (e); diff --git a/gcc/testsuite/gcc.target/i386/pr95778-1.c b/gcc/testsuite/gcc.target/i386/pr95778-1.c new file mode 100644 index 00000000000..3238303d696 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr95778-1.c @@ -0,0 +1,21 @@ +/* { dg-do compile { target fpic } } */ +/* { dg-options "-O3 -fPIC -fno-asynchronous-unwind-tables" } */ +/* { dg-require-ifunc "" } */ + +__attribute__((target_clones("default,avx2"))) +static int +f2(int *p) +{ + asm volatile ("" :: "r"(p) : "memory"); + return *p; +} + +__attribute__((target_clones("default,avx2"))) +int +g2(int *p) +{ + return f2(p); +} + +/* { dg-final { scan-assembler "g2.default.1:\n\tjmp\tf2.default.1\n" } } */ +/* { dg-final { scan-assembler "g2.avx2.0:\n\tjmp\tf2.avx2.0\n" } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr95778-2.c b/gcc/testsuite/gcc.target/i386/pr95778-2.c new file mode 100644 index 00000000000..e88702d2b82 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr95778-2.c @@ -0,0 +1,21 @@ +/* { dg-do compile { target fpic } } */ +/* { dg-options "-O3 -fPIC -fno-asynchronous-unwind-tables" } */ +/* { dg-require-ifunc "" } */ + +__attribute__((visibility("internal"),target_clones("default,avx2"))) +int +f2(int *p) +{ + asm volatile ("" :: "r"(p) : "memory"); + return *p; +} + +__attribute__((target_clones("default,avx2"))) +int +g2(int *p) +{ + return f2(p); +} + +/* { dg-final { scan-assembler "g2.default.1:\n\tjmp\tf2.default.1\n" } } */ +/* { dg-final { scan-assembler "g2.avx2.0:\n\tjmp\tf2.avx2.0\n" } } */