From patchwork Wed Jan 4 09:20:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 38815 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5047820wrt; Wed, 4 Jan 2023 01:21:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXuwORn7u351FjRdNrKlBUDvECgz4OahI2vFtGDnFuqwdi5Aq87tHVAEgPcqxMwXkbRAd+P6 X-Received: by 2002:a17:907:170c:b0:7c1:2478:a4d8 with SMTP id le12-20020a170907170c00b007c12478a4d8mr41842228ejc.54.1672824101482; Wed, 04 Jan 2023 01:21:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672824101; cv=none; d=google.com; s=arc-20160816; b=wCQenHIqx65rZbzJu6jjSopczWDz7oj64hAz49rZyi5WlE0NtXUjHDUFb+ThRw/UNi E4heODoQZbKWJwE/GKcGokPRW4KLunV01LOjXJohhEpw1e119KxA0F/d4jivSWIleJR3 BwO0pvQMRi+wH2fMEWImwL/U0kovynFQbodr4Xv3fQLz3h6upJEHVfxP2GA1CGtSk/io upKJidb+eAZVTVUYQjmvm8X82g0JKmfrtzy0jX5VYWJrlP6bFXW/YfQTViINpTwPzfpN RTp36bCjpH2RLvCxg8G1jLiG/+Zrg87w6pP+sIHCub1XLfZ87a11v6236QiRHwhoCgOb 2PCw== 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:cc:to:subject:content-language:user-agent :date:message-id:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=XkavJiWIPfQrxvizybQ1caVbzvMqMfGLxrOFJq4Yjsg=; b=WJq6mEFMqUhD0suR3lA54FvxuMoQHcuhbrsQX4Du5/vi10okhu8Tffo9DGoU+oIJg7 Rb4MudJKWlSKb3ZJoxiy8/HMKCrur+I25ugQCKrgJjxPpA5MrXbM5j4j2HvzR8aGhool CNqQn9NgBAIvGfMIJ9KKiLbMJbamACtvDSXpE7Ez0sV89N5Gr9YF1Bv4wzYoq750mXXY KJwjs2gyn7R+li14lP6CPudp8JuEs7nVQ3/zrNgsDSkWKLNNwGyvxdPmz4zF+GweOyew /ITGyCfe5sjlY9ft/4U0QVmlYliyRsDhDdEIpuUbjX71LSFhJdhYWntBTh5RsnubVQrS 8gzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZHRD52GH; 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 s15-20020a056402164f00b0048b8e656038si10633487edx.383.2023.01.04.01.21.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 01:21:41 -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=ZHRD52GH; 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 4716B38438AB for ; Wed, 4 Jan 2023 09:21:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4716B38438AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672824070; bh=XkavJiWIPfQrxvizybQ1caVbzvMqMfGLxrOFJq4Yjsg=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ZHRD52GHMHEJ02RylvrsF0EsICuFq+FisvaEmfi2eAC49a1XBSE2FiRff57gsjqrL mcUKBakK/UqPE0qIBlMiTxskQRXRe1X4Kv9fzT+Vu8wgrRAtRNSy1xEo5rdMMOcv0z T1eQlS8pORYuHGycSS7jJ+PMtwLXNkPCBX9s2Lag= 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 47C6A3858D35 for ; Wed, 4 Jan 2023 09:20:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 47C6A3858D35 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 304986X2032587; Wed, 4 Jan 2023 09:20:23 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mvjk2t0m4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Jan 2023 09:20:22 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3049ChrV029528; Wed, 4 Jan 2023 09:20:22 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mvjk2t0k9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Jan 2023 09:20:22 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 303LSh6u001912; Wed, 4 Jan 2023 09:20:20 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3mtcq6d1qk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Jan 2023 09:20:19 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3049KH9i21496180 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Jan 2023 09:20:17 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 882E120043; Wed, 4 Jan 2023 09:20:17 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F040D20040; Wed, 4 Jan 2023 09:20:15 +0000 (GMT) Received: from [9.200.36.187] (unknown [9.200.36.187]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 4 Jan 2023 09:20:15 +0000 (GMT) Message-ID: <197abd1f-081c-3206-4dd5-45f0b098612a@linux.ibm.com> Date: Wed, 4 Jan 2023 17:20:14 +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 Subject: [PATCH] rs6000: Don't use optimize_function_for_speed_p too early [PR108184] To: GCC Patches Cc: Segher Boessenkool , David Edelsohn , Peter Bergner X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: -QyrODPbU_l-VzcP5yzga8YXdLSAlmu8 X-Proofpoint-GUID: 7Z7z1Z5eVGAccOIkhARtmNLlPFSFAFO- 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=2023-01-04_04,2023-01-03_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 suspectscore=0 bulkscore=0 impostorscore=0 mlxscore=0 adultscore=0 clxscore=1015 spamscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301040076 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, 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?1754083204995318548?= X-GMAIL-MSGID: =?utf-8?q?1754083204995318548?= Hi, As Honza pointed out in [1], the current uses of function optimize_function_for_speed_p in rs6000_option_override_internal are too early, since the query results from the functions optimize_function_for_{speed,size}_p could be changed later due to profile feedback and some function attributes handlings etc. This patch is to move optimize_function_for_speed_p to all the use places of the corresponding flags, which follows the existing practices. Maybe we can cache it somewhere at an appropriate timing, but that's another thing. [1] https://gcc.gnu.org/pipermail/gcc-patches/2022-November/607527.html Bootstrapped and regtested on powerpc64-linux-gnu P8 and powerpc64le-linux-gnu P9 and P10. I'm going to push this soon if no objections. BR, Kewen ----- PR target/108184 gcc/ChangeLog: * config/rs6000/rs6000.cc (rs6000_option_override_internal): Remove all optimize_function_for_speed_p uses. * config/rs6000/predicates.md (fusion_gpr_mem_load): Call optimize_function_for_speed_p along with TARGET_P8_FUSION_SIGN. (fusion_gpr_load_p): Likewise. (expand_fusion_gpr_load): Likewise. (rs6000_call_aix): Call optimize_function_for_speed_p along with TARGET_SAVE_TOC_INDIRECT. gcc/testsuite/ChangeLog: * gcc.target/powerpc/pr108184.c: New test. --- gcc/config/rs6000/predicates.md | 4 +++- gcc/config/rs6000/rs6000.cc | 16 ++++++++++------ gcc/testsuite/gcc.target/powerpc/pr108184.c | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108184.c -- 2.27.0 diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md index b1fcc69bb60..11f1779e7bf 100644 --- a/gcc/config/rs6000/predicates.md +++ b/gcc/config/rs6000/predicates.md @@ -1878,7 +1878,9 @@ (define_predicate "fusion_gpr_mem_load" /* Handle sign/zero extend. */ if (GET_CODE (op) == ZERO_EXTEND - || (TARGET_P8_FUSION_SIGN && GET_CODE (op) == SIGN_EXTEND)) + || (TARGET_P8_FUSION_SIGN + && GET_CODE (op) == SIGN_EXTEND + && optimize_function_for_speed_p (cfun))) { op = XEXP (op, 0); mode = GET_MODE (op); diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index eb7ad5e954f..bbf829f45d9 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -3978,8 +3978,7 @@ rs6000_option_override_internal (bool global_init_p) /* If we can shrink-wrap the TOC register save separately, then use -msave-toc-indirect unless explicitly disabled. */ if ((rs6000_isa_flags_explicit & OPTION_MASK_SAVE_TOC_INDIRECT) == 0 - && flag_shrink_wrap_separate - && optimize_function_for_speed_p (cfun)) + && flag_shrink_wrap_separate) rs6000_isa_flags |= OPTION_MASK_SAVE_TOC_INDIRECT; /* Enable power8 fusion if we are tuning for power8, even if we aren't @@ -4013,7 +4012,6 @@ rs6000_option_override_internal (bool global_init_p) zero extending load, and an explicit sign extension. */ if (TARGET_P8_FUSION && !(rs6000_isa_flags_explicit & OPTION_MASK_P8_FUSION_SIGN) - && optimize_function_for_speed_p (cfun) && optimize >= 3) rs6000_isa_flags |= OPTION_MASK_P8_FUSION_SIGN; @@ -25604,7 +25602,9 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) /* Can we optimize saving the TOC in the prologue or do we need to do it at every call? */ - if (TARGET_SAVE_TOC_INDIRECT && !cfun->calls_alloca) + if (TARGET_SAVE_TOC_INDIRECT + && !cfun->calls_alloca + && optimize_function_for_speed_p (cfun)) cfun->machine->save_toc_in_prologue = true; else { @@ -27471,7 +27471,9 @@ fusion_gpr_load_p (rtx addis_reg, /* register set via addis. */ /* Allow sign/zero extension. */ if (GET_CODE (mem) == ZERO_EXTEND - || (GET_CODE (mem) == SIGN_EXTEND && TARGET_P8_FUSION_SIGN)) + || (GET_CODE (mem) == SIGN_EXTEND + && TARGET_P8_FUSION_SIGN + && optimize_function_for_speed_p (cfun))) mem = XEXP (mem, 0); if (!MEM_P (mem)) @@ -27535,7 +27537,9 @@ expand_fusion_gpr_load (rtx *operands) enum rtx_code extend = UNKNOWN; if (GET_CODE (orig_mem) == ZERO_EXTEND - || (TARGET_P8_FUSION_SIGN && GET_CODE (orig_mem) == SIGN_EXTEND)) + || (TARGET_P8_FUSION_SIGN + && GET_CODE (orig_mem) == SIGN_EXTEND + && optimize_function_for_speed_p (cfun))) { extend = GET_CODE (orig_mem); orig_mem = XEXP (orig_mem, 0); diff --git a/gcc/testsuite/gcc.target/powerpc/pr108184.c b/gcc/testsuite/gcc.target/powerpc/pr108184.c new file mode 100644 index 00000000000..8f1e91d9258 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr108184.c @@ -0,0 +1,15 @@ +/* Only possible to fuse sign extended loads with the addis when + optimize >= 3 and Power8 fusion takes effects. */ +/* { dg-options "-mdejagnu-tune=power8 -O3" } */ + +/* Verify it doesn't optimize this function for speed as it's cold, + by checking it doesn't try to fuse sign extended loads with addis, + which results in a zero extended load and a sign extension. */ + +__attribute__ ((cold)) int +fusion_short (short *p) +{ + return p[0x12345]; +} + +/* { dg-final { scan-assembler-not {\mextsh\M} } } */