From patchwork Wed Nov 30 08:30:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 27672 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp799665wrr; Wed, 30 Nov 2022 00:31:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf7mTunbeKihsg5jqVHspc/qKvzkE5LTrGT2UVlLdAxK5ljRJCoJZlHhknMvbgSoqCcdfQ/W X-Received: by 2002:a17:906:18e9:b0:78d:48ac:9044 with SMTP id e9-20020a17090618e900b0078d48ac9044mr39326341ejf.613.1669797115080; Wed, 30 Nov 2022 00:31:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669797115; cv=none; d=google.com; s=arc-20160816; b=D1hqfCF2iwuJiBVaKNSVbwD6avmU2UWRB0TIdgFyhbRUu1fCimS4oEdtR4yZ4kVTyB 5km+Kp57c/tzAIrFdv5NKqQF9nQYgfA0/P97YzNPng9JMYy5Z8W0gDkQYFo2l7/ZU6WL VhMmJ+ysBMMA7/6Lq7PMR4/mq4OCDb0iDHJQiCo8zITpVHXanSMoIxP/wLUtO7z3iVq6 ltMeqW9iY2zUjCSIdC0rhA4VGtuApr8u5TdqlXot9hbwtAu7CMhOYccD8gSt0efz3kDq JzlUcrsN1ynCSMfw4P7fYFTjCUbcSNmMdv7hy2RozSrfHD/lbM4nmjb7WnrquxpbWv17 VM5A== 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:mime-version :content-transfer-encoding:subject:cc:to:content-language:user-agent :date:message-id:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=7zgJt9lw1oGDIjo9EyKLtQLtCVs7J/q1gX5c+AComjo=; b=JQCD3WljkQwTuBgDlJfCjkk0LoTtJ01Saad99ReqBB5k/XjziUv2WCvAhX1t1AsUtk Lre7tyUqnYGvd/fg4CrR88UFtjVbSBZgStrC+47/q03FnYk5sULmgp/uU81SXwCps5pF MPRwZAIovBroHBwVN7Psg4vROK5bunD5w6pz/Tj2xBEV72iuLXMnNQVQ41uXkV/kaHoF JDCmFHhee7eyaafdvLqBk3mFENIqgoZWzV1t6FpCftZHTJduZkhQnML5Hp7uE7qPOTHz D4GeAkxvUuQ41buBnMUc8b5yD7LmbysJtEOT1Y+DPSm67HWDMYgMjeEUBBU1o3I3k/ci uuZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gdLi3zWP; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fi16-20020a056402551000b0046b5106d52esi668106edb.467.2022.11.30.00.31.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 00:31:55 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gdLi3zWP; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 A9FDA38582AB for ; Wed, 30 Nov 2022 08:31:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9FDA38582AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669797110; bh=7zgJt9lw1oGDIjo9EyKLtQLtCVs7J/q1gX5c+AComjo=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=gdLi3zWPkv+10NfdEdai6g3mbJU/zgk6T/KcI8AmHOf3hO1z3JZ2RtwXxlVuTRaxr ya3uWY+ggXn963b82Ya+7/T4s9s3DrfYAjumxLkohH5MPdX3hZ5D+6n8CYthxJNitd TLSUHRZr5eeTFVXGtSqEW79fh+JdBJjM3i2Wb5fM= 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 7D18C3857BB3 for ; Wed, 30 Nov 2022 08:30:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7D18C3857BB3 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AU5lmxw020609; Wed, 30 Nov 2022 08:30:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m61bfkgn3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Nov 2022 08:30:53 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2AU7x3K6031411; Wed, 30 Nov 2022 08:30:53 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m61bfkgks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Nov 2022 08:30:52 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2AU8KCga018256; Wed, 30 Nov 2022 08:30:50 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06ams.nl.ibm.com with ESMTP id 3m3a2hwft7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Nov 2022 08:30:50 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2AU8Um4j4719242 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Nov 2022 08:30:48 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 17C4BAE051; Wed, 30 Nov 2022 08:30:48 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9B8CEAE045; Wed, 30 Nov 2022 08:30:45 +0000 (GMT) Received: from [9.197.238.163] (unknown [9.197.238.163]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 30 Nov 2022 08:30:45 +0000 (GMT) Message-ID: Date: Wed, 30 Nov 2022 16:30:44 +0800 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: Jan Hubicka , Richard Biener , Richard Sandiford , Segher Boessenkool , Peter Bergner Subject: [PATCH v2] predict: Adjust optimize_function_for_size_p [PR105818] X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 23kXA9QapnMjPM8SCg9IaJB5osj8jWwv X-Proofpoint-GUID: S0FBQbMlC20rCKWbk9cTdUkWEx31HjAP X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-30_04,2022-11-29_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 impostorscore=0 mlxlogscore=890 phishscore=0 malwarescore=0 clxscore=1011 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211300061 X-Spam-Status: No, score=-11.7 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750909179645756767?= X-GMAIL-MSGID: =?utf-8?q?1750909179645756767?= 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 -- 2.27.0 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); +}