From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : to : cc : from : subject : content-type : content-transfer-encoding; s=pp1; bh=GchMi/fu+jzgCIa0S9wG55g/VMYNb4nuuWmyqxJl7Aw=; b=IUzGqo7miYJyqWM0ES0GWl3Dw1TqDACXzAbFlMSIHN4Nc4iS2KJKsW5Bv7Ky6migFuXl Jo0YrRt4ahzoOymxltFgg8H/5mr6INLyM2waSNdBygQKpx1V5lWUypE9aK7M5wohfQfm nlsLwsi1nd/oE6PdXSCQJsdS9I5qmsOM1Kl2fBU1qEnoe3V+MaRm4KPKOxg/gSCC2X7z iNL4cApOkJt4T5JYxTGlV2D05+ja4q4avUGFlfoZOK7OIUxtP/jDNKkwVe1Owlu24dXX O1vI5pmXud+tlBezMfwL8suTYm7AKP52DDXyOeu1KWF2NCmR4f1BxdNzrjnnCvIXJQfU BA== 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 From: "Kewen.Lin" Subject: [PATCH] rs6000: Use default target option node for callee by default [PR111380] Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 List-Id: 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 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; +} -- 2.31.1