From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id AC03838308DD for ; Wed, 14 Dec 2022 11:27:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AC03838308DD 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 (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BEBHqB3016985; Wed, 14 Dec 2022 11:27:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pp1; bh=X5AFu2IXtE7cu7mD1N6F3V71eICs5lcfLw9inUM2kf8=; b=Q4x8pQ9VYKduhpn/Aytpc+mkHUz3xHpm63bqeWc7J0bIGq16XyEfXoLUs+T3ysS9sJ9E +nfvEzSiMVE/RgZc9CcEplrTRdhreAeVJ5szvkgAQGgczigkoTiDLBWrknqlI1C0jNwW 4F8Y4oPvagaqxv55htruZxv41huyLg7CopqX+B54Txo96A1FS6QHg5OQpwRzKHkOpkY+ bdcIkwgBRrHWE2heOlgtS+eKUuZtVdCVclenCM0MyqMdC0c1a59AyrdaOqnJKBvnGV8/ 3JdoRGHNuQk8QLfl1iW6/5rEvEteFTUxEUlsKm5yZt/2/MnpV38Ji78BoEj4d12DgvfM GA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mfdg5g5qk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Dec 2022 11:27:13 +0000 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2BEBHrfN017003; Wed, 14 Dec 2022 11:27:12 GMT Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mfdg5g5pt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Dec 2022 11:27:12 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 2BDJqvR8030594; Wed, 14 Dec 2022 11:27:10 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma05fra.de.ibm.com (PPS) with ESMTPS id 3meyxm8t8n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Dec 2022 11:27:10 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2BEBR8vQ51773732 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Dec 2022 11:27:08 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2EACE2004E; Wed, 14 Dec 2022 11:27:08 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 076512004B; Wed, 14 Dec 2022 11:27:06 +0000 (GMT) Received: from [9.197.253.236] (unknown [9.197.253.236]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 14 Dec 2022 11:27:05 +0000 (GMT) Message-ID: <64451523-8036-6d9a-b990-e07746867efd@linux.ibm.com> Date: Wed, 14 Dec 2022 19:27:04 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: PING^1 [PATCH v2] predict: Adjust optimize_function_for_size_p [PR105818] Content-Language: en-US To: GCC Patches Cc: Jan Hubicka , Richard Biener , Richard Sandiford , Segher Boessenkool , Peter Bergner References: From: "Kewen.Lin" In-Reply-To: Content-Type: text/plain; charset=UTF-8 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: PmxBHPcpTfsIlkZuo198wnO4IuNA9OJ3 X-Proofpoint-GUID: L37s2GP4twanv8guDWUFoj9lW_4zqCbz Content-Transfer-Encoding: 7bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-14_04,2022-12-14_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 suspectscore=0 clxscore=1015 adultscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212140087 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_MSPIKE_H2,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, Gentle ping: https://gcc.gnu.org/pipermail/gcc-patches/2022-November/607527.html BR, Kewen on 2022/11/30 16:30, Kewen.Lin via Gcc-patches wrote: > Hi, > > Function optimize_function_for_size_p returns OPTIMIZE_SIZE_NO > if fun->decl is not null but no cgraph node is available for it. > As PR105818 shows, this could cause unexpected consequence. For > the case in PR105818, when parsing bar decl in function foo, the > cfun is the function structure for foo, for which there is no > cgraph node, so it returns OPTIMIZE_SIZE_NO. But it's incorrect > since the context is to optimize for size, the flag optimize_size > is true. > > The patch is to make optimize_function_for_size_p to check > opt_for_fn (fun->decl, optimize_size) further when fun->decl > is available but no cgraph node, it's just like what function > cgraph_node::optimize_for_size_p does at its first step. > > One regression failure got exposed on aarch64-linux-gnu: > > PASS->FAIL: gcc.dg/guality/pr54693-2.c -Os \ > -DPREVENT_OPTIMIZATION line 21 x == 10 - i > > The difference comes from the macro LOGICAL_OP_NON_SHORT_CIRCUIT > used in function fold_range_test during c parsing, it uses > optimize_function_for_speed_p which is equal to the invertion > of optimize_function_for_size_p. At that time cfun->decl is valid > but no cgraph node for it, w/o this patch function > optimize_function_for_speed_p returns true eventually, while it > returns false with this patch. Since the command line option -Os > is specified, there is no reason to interpret it as "for speed". > I think this failure is expected and adjust the test case > accordingly. > > v1: https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596628.html > > Comparing with v1, v2 adopts opt_for_fn (fun->decl, optimize_size) > instead of optimize_size as Honza's previous comments. > > Besides, the reply to Honza's question "Why exactly PR105818 hits > the flag change issue?" was at the link: > https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596667.html > > Bootstrapped and regtested on x86_64-redhat-linux, > aarch64-linux-gnu and powerpc64{,le}-linux-gnu. > > Is it for trunk? > > BR, > Kewen > ----- > PR middle-end/105818 > > gcc/ChangeLog: > > * predict.cc (optimize_function_for_size_p): Further check > optimize_size of fun->decl when it is valid but no cgraph node. > > gcc/testsuite/ChangeLog: > > * gcc.target/powerpc/pr105818.c: New test. > * gcc.dg/guality/pr54693-2.c: Adjust for aarch64. > --- > gcc/predict.cc | 3 ++- > gcc/testsuite/gcc.dg/guality/pr54693-2.c | 2 +- > gcc/testsuite/gcc.target/powerpc/pr105818.c | 11 +++++++++++ > 3 files changed, 14 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/powerpc/pr105818.c > > diff --git a/gcc/predict.cc b/gcc/predict.cc > index 1bc7ab94454..ecb4aabc9df 100644 > --- a/gcc/predict.cc > +++ b/gcc/predict.cc > @@ -268,7 +268,8 @@ optimize_function_for_size_p (struct function *fun) > cgraph_node *n = cgraph_node::get (fun->decl); > if (n) > return n->optimize_for_size_p (); > - return OPTIMIZE_SIZE_NO; > + return opt_for_fn (fun->decl, optimize_size) ? OPTIMIZE_SIZE_MAX > + : OPTIMIZE_SIZE_NO; > } > > /* Return true if function FUN should always be optimized for speed. */ > diff --git a/gcc/testsuite/gcc.dg/guality/pr54693-2.c b/gcc/testsuite/gcc.dg/guality/pr54693-2.c > index 68aa6c63d71..14ca94ad37d 100644 > --- a/gcc/testsuite/gcc.dg/guality/pr54693-2.c > +++ b/gcc/testsuite/gcc.dg/guality/pr54693-2.c > @@ -17,7 +17,7 @@ foo (int x, int y, int z) > int i = 0; > while (x > 3 && y > 3 && z > 3) > { /* { dg-final { gdb-test .+2 "i" "v + 1" } } */ > - /* { dg-final { gdb-test .+1 "x" "10 - i" } } */ > + /* { dg-final { gdb-test .+1 "x" "10 - i" { xfail { aarch64*-*-* && { any-opts "-Os" } } } } } */ > bar (i); /* { dg-final { gdb-test . "y" "20 - 2 * i" } } */ > /* { dg-final { gdb-test .-1 "z" "30 - 3 * i" { xfail { aarch64*-*-* && { any-opts "-fno-fat-lto-objects" "-Os" } } } } } */ > i++, x--, y -= 2, z -= 3; > diff --git a/gcc/testsuite/gcc.target/powerpc/pr105818.c b/gcc/testsuite/gcc.target/powerpc/pr105818.c > new file mode 100644 > index 00000000000..679647e189d > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/pr105818.c > @@ -0,0 +1,11 @@ > +/* { dg-options "-Os -fno-tree-vectorize" } */ > + > +/* Verify there is no ICE. */ > + > +#pragma GCC optimize "-fno-tree-vectorize" > + > +void > +foo (void) > +{ > + void bar (void); > +} > -- > 2.27.0