From patchwork Mon Sep 18 06:26:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 141255 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2463284vqi; Sun, 17 Sep 2023 23:27:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2kz8Surj6W4UA4zXjEkJXUHQYhMBX32BT7oC7LOw9Pt6rm2iEr9wMO41aubNdzsP6oDDN X-Received: by 2002:a05:6402:4019:b0:530:f296:d446 with SMTP id d25-20020a056402401900b00530f296d446mr2762863eda.34.1695018444693; Sun, 17 Sep 2023 23:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695018444; cv=none; d=google.com; s=arc-20160816; b=qqIJRlOm624PYRg9WXgoDddoqkZP6x0IGaFYT20oQshjOQ9J9HFmcWi48noiU2/YYI Lk3Kb7R5xAMG75Fjffhz4cfueBHmgW4fbz5qHvwxzUT20wMrrWEd6D1UVpl6/8/QCd2l o6zm8HwxndwQKrvcy+FKuI1lsBWGWVv2UDw46/MK+Er7bIB4hQoEdTlc7RmItrpaP2UV fNY0d+jL/ZmcTp4tLMpEAzr3GOH//ShhVZGYvPjuRIKbSgv0otzTxXwejPMjUKTeiDJy 9574U+IX2rFG+CffM7onlAlxwCcO7AEZmm18YlyO52LKXOm5TEwEboxjjx3BXhk6HW3l ZPqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:subject:cc:to:content-language:user-agent :mime-version:date:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=GchMi/fu+jzgCIa0S9wG55g/VMYNb4nuuWmyqxJl7Aw=; fh=TYscnGqW0KApfv6ZlemA7et4nVHZawC2xDR9ijCT1JQ=; b=o/IaheDcgayRLUNuYSU68VnaKGnA5Q+DYO9S4m74BQ855VOlRgiGvbFDMJhGSJzO7K kP59rub995CF3zIW9HQgmqaZlztYMO5hxP/8D0acZTjSe6vWIM3fpQiwAza6fBKwMXjU nPEBwN/iswh//VPJd+DwnFaBe2lniGLKsuu0x5UZqEn7Q6tM3Rs0+4Z6ZEtkFXW7CReH htMiv03NgRtrNVEGaBw/AG7zYz2YZp6tA9zYZ/wJ5bwan2ARhTZtujOoUaaahrCfzA/G bYsxL/TC3LPr3T5gMqNYhEGsq17xiso1YLD5qpzBJAVygx4bEzVCaJlsAQmavrwDCHRP CNcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xTVAMp3t; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id s20-20020a056402015400b0052eab0753c4si7290594edu.626.2023.09.17.23.27.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 23:27:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xTVAMp3t; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7257A3857438 for ; Mon, 18 Sep 2023 06:27:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7257A3857438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695018437; bh=GchMi/fu+jzgCIa0S9wG55g/VMYNb4nuuWmyqxJl7Aw=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=xTVAMp3tMqzjfJfnOzPhjeq7HllNyopmlaJQRukwIqHvFwkDJBHK+gty5RoMZp2IZ fDMOe4X/d7aJdhqKdyVJGTnZ/hd2iFslBZWQN5VZHx4aBUoJzhexWk2XY+1sEWgxV5 XGbRV8XPprY/GP0fp9kj1xTpTzVjGpgOLvA1TT9w= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id D64E23858D32 for ; Mon, 18 Sep 2023 06:26:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D64E23858D32 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38I68Okj001651; Mon, 18 Sep 2023 06:26:30 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3t6g770y3x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Sep 2023 06:26:30 +0000 Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 38I6A2Rd004133; Mon, 18 Sep 2023 06:26:29 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3t6g770y3m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Sep 2023 06:26:29 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 38I3VZsm018211; Mon, 18 Sep 2023 06:26:28 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3t5pps8rkd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Sep 2023 06:26:28 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 38I6QPVa26477206 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Sep 2023 06:26:25 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 81DDB2004D; Mon, 18 Sep 2023 06:26:25 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6E36420040; Mon, 18 Sep 2023 06:26:23 +0000 (GMT) Received: from [9.177.92.215] (unknown [9.177.92.215]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 18 Sep 2023 06:26:23 +0000 (GMT) Message-ID: Date: Mon, 18 Sep 2023 14:26:21 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US To: GCC Patches Cc: Segher Boessenkool , Peter Bergner , David Edelsohn , Michael Meissner Subject: [PATCH] rs6000: Use default target option node for callee by default [PR111380] X-TM-AS-GCONF: 00 X-Proofpoint-GUID: SkekIzwl4hw1MBn1YhxjNNftg4ej47aP X-Proofpoint-ORIG-GUID: QheF0c_V1TMwfJD94z4h5lG4dMUUSRU3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-15_20,2023-09-15_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 phishscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 mlxlogscore=861 priorityscore=1501 clxscore=1015 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309180054 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Kewen.Lin via Gcc-patches" From: "Kewen.Lin" Reply-To: "Kewen.Lin" Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777355660435482955 X-GMAIL-MSGID: 1777355660435482955 Hi, As PR111380 (and the discussion in related PRs) shows, for now how function rs6000_can_inline_p treats the callee without any target option node is wrong. It considers it's always safe to inline this kind of callee, but actually its target flags are from the command line options (target_option_default_node), it's possible that the flags of callee don't satisfy the condition of inlining, but it is still inlined, then result in unexpected consequence. As the associated test case pr111380-1.c shows, the caller main is attributed with power8, but the callee foo is compiled with power9 from command line, it's unexpected to make main inline foo since foo can contain something that requires power9 capability. Without this patch, for lto (with -flto) we can get error message (as it forces the callee to have a target option node), but for non-lto, it's inlined unexpectedly. This patch is to make callee adopt target_option_default_node when it doesn't have a target option node, it can avoid wrong inlining decision and fix the inconsistency between LTO and non-LTO. It also aligns with what the other ports do. Bootstrapped and regtested on powerpc64-linux-gnu P7/P8/P9 and powerpc64le-linux-gnu P9 and P10. I'm going to push this soon if no objections. BR, Kewen ----- PR target/111380 gcc/ChangeLog: * config/rs6000/rs6000.cc (rs6000_can_inline_p): Adopt target_option_default_node when the callee has no option attributes, also simplify the existing code accordingly. gcc/testsuite/ChangeLog: * gcc.target/powerpc/pr111380-1.c: New test. * gcc.target/powerpc/pr111380-2.c: New test. --- gcc/config/rs6000/rs6000.cc | 65 +++++++++---------- gcc/testsuite/gcc.target/powerpc/pr111380-1.c | 20 ++++++ gcc/testsuite/gcc.target/powerpc/pr111380-2.c | 20 ++++++ 3 files changed, 70 insertions(+), 35 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr111380-1.c create mode 100644 gcc/testsuite/gcc.target/powerpc/pr111380-2.c -- 2.31.1 diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index efe9adce1f8..d48134b35f8 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -25508,49 +25508,44 @@ rs6000_can_inline_p (tree caller, tree callee) tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller); tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee); - /* If the callee has no option attributes, then it is ok to inline. */ + /* If the caller/callee has option attributes, then use them. + Otherwise, use the command line options. */ if (!callee_tree) - ret = true; + callee_tree = target_option_default_node; + if (!caller_tree) + caller_tree = target_option_default_node; - else - { - HOST_WIDE_INT caller_isa; - struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree); - HOST_WIDE_INT callee_isa = callee_opts->x_rs6000_isa_flags; - HOST_WIDE_INT explicit_isa = callee_opts->x_rs6000_isa_flags_explicit; + struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree); + struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree); - /* If the caller has option attributes, then use them. - Otherwise, use the command line options. */ - if (caller_tree) - caller_isa = TREE_TARGET_OPTION (caller_tree)->x_rs6000_isa_flags; - else - caller_isa = rs6000_isa_flags; + HOST_WIDE_INT callee_isa = callee_opts->x_rs6000_isa_flags; + HOST_WIDE_INT caller_isa = caller_opts->x_rs6000_isa_flags; + HOST_WIDE_INT explicit_isa = callee_opts->x_rs6000_isa_flags_explicit; - cgraph_node *callee_node = cgraph_node::get (callee); - if (ipa_fn_summaries && ipa_fn_summaries->get (callee_node) != NULL) + cgraph_node *callee_node = cgraph_node::get (callee); + if (ipa_fn_summaries && ipa_fn_summaries->get (callee_node) != NULL) + { + unsigned int info = ipa_fn_summaries->get (callee_node)->target_info; + if ((info & RS6000_FN_TARGET_INFO_HTM) == 0) { - unsigned int info = ipa_fn_summaries->get (callee_node)->target_info; - if ((info & RS6000_FN_TARGET_INFO_HTM) == 0) - { - callee_isa &= ~OPTION_MASK_HTM; - explicit_isa &= ~OPTION_MASK_HTM; - } + callee_isa &= ~OPTION_MASK_HTM; + explicit_isa &= ~OPTION_MASK_HTM; } + } - /* Ignore -mpower8-fusion and -mpower10-fusion options for inlining - purposes. */ - callee_isa &= ~(OPTION_MASK_P8_FUSION | OPTION_MASK_P10_FUSION); - explicit_isa &= ~(OPTION_MASK_P8_FUSION | OPTION_MASK_P10_FUSION); + /* Ignore -mpower8-fusion and -mpower10-fusion options for inlining + purposes. */ + callee_isa &= ~(OPTION_MASK_P8_FUSION | OPTION_MASK_P10_FUSION); + explicit_isa &= ~(OPTION_MASK_P8_FUSION | OPTION_MASK_P10_FUSION); - /* The callee's options must be a subset of the caller's options, i.e. - a vsx function may inline an altivec function, but a no-vsx function - must not inline a vsx function. However, for those options that the - callee has explicitly enabled or disabled, then we must enforce that - the callee's and caller's options match exactly; see PR70010. */ - if (((caller_isa & callee_isa) == callee_isa) - && (caller_isa & explicit_isa) == (callee_isa & explicit_isa)) - ret = true; - } + /* The callee's options must be a subset of the caller's options, i.e. + a vsx function may inline an altivec function, but a no-vsx function + must not inline a vsx function. However, for those options that the + callee has explicitly enabled or disabled, then we must enforce that + the callee's and caller's options match exactly; see PR70010. */ + if (((caller_isa & callee_isa) == callee_isa) + && (caller_isa & explicit_isa) == (callee_isa & explicit_isa)) + ret = true; if (TARGET_DEBUG_TARGET) fprintf (stderr, "rs6000_can_inline_p:, caller %s, callee %s, %s inline\n", diff --git a/gcc/testsuite/gcc.target/powerpc/pr111380-1.c b/gcc/testsuite/gcc.target/powerpc/pr111380-1.c new file mode 100644 index 00000000000..57ae75ef73a --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr111380-1.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9" } */ + +/* Verify it emits error message on inlining even without LTO. */ + +vector int c, a, b; + +static inline void __attribute__ ((__always_inline__)) +foo () /* { dg-error "inlining failed in call to .* target specific option mismatch" } */ +{ + c = a + b; +} + +__attribute__ ((target ("cpu=power8"))) +int main () +{ + foo (); /* { dg-message "called from here" } */ + c = a + b; +} diff --git a/gcc/testsuite/gcc.target/powerpc/pr111380-2.c b/gcc/testsuite/gcc.target/powerpc/pr111380-2.c new file mode 100644 index 00000000000..7b363940643 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr111380-2.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-options "-O2 -mno-vsx" } */ + +/* Verify it emits error message on inlining even without LTO. */ + +vector int c, a, b; + +static inline void __attribute__ ((__always_inline__)) +foo () /* { dg-error "inlining failed in call to .* target specific option mismatch" } */ +{ + c = a + b; +} + +__attribute__ ((target ("vsx"))) +int main () +{ + foo (); /* { dg-message "called from here" } */ + c = a + b; +}