From patchwork Tue Apr 5 22:06:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Bergner X-Patchwork-Id: 1613596 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=yCcUfopB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KY1w94G2mz9sFk for ; Wed, 6 Apr 2022 08:07:19 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0DA833858016 for ; Tue, 5 Apr 2022 22:07:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DA833858016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1649196438; bh=a5DcsKrCRn8L+chvnme2WS2i9ZxqHere8R62pLJSQn0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=yCcUfopBD24wgjtpx6PcvZ/ggElSPntMRj66+1Et5vNeiskh82cQTKeTSL1JCqLim WRJS+fOeCiriugzJYTAo0OFX17ryz68+1QYY9d71UFyX4WJKIWyyR6iREfA1O8LXoc toVUEb1jrcd24XzXHXzjRbden23chL1IvUcBzel4= 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 0CDFC3858D37 for ; Tue, 5 Apr 2022 22:06:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0CDFC3858D37 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 235Kjs4t001158; Tue, 5 Apr 2022 22:06:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f8w3es8g8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Apr 2022 22:06:53 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 235LUbwG008957; Tue, 5 Apr 2022 22:06:53 GMT Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f8w3es8fv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Apr 2022 22:06:53 +0000 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 235Lx6at014633; Tue, 5 Apr 2022 22:06:52 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma02dal.us.ibm.com with ESMTP id 3f6e4ah467-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Apr 2022 22:06:52 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 235M6pa012779990 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Apr 2022 22:06:51 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6DB327805E; Tue, 5 Apr 2022 22:06:51 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CB8BA78063; Tue, 5 Apr 2022 22:06:50 +0000 (GMT) Received: from [9.77.152.28] (unknown [9.77.152.28]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 5 Apr 2022 22:06:50 +0000 (GMT) Message-ID: <23cc030c-608a-8593-71a9-ec90f13938d0@linux.ibm.com> Date: Tue, 5 Apr 2022 17:06:50 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: Segher Boessenkool , David Edelsohn Subject: [PATCH] rs6000: Handle pcrel sibcalls to longcall functions [PR104894] X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ADJ_2nBcYAFklP03FyRJ3BQ6C8lD70yo X-Proofpoint-ORIG-GUID: jE7NE-Va89l0leSqFv7uPjc5SOjCglKq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-04-05_08,2022-04-05_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 phishscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204050119 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Peter Bergner via Gcc-patches From: Peter Bergner Reply-To: Peter Bergner Cc: GCC Patches , Alan Modra Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Before PCREL in POWER10, we were not allowed to perform sibcalls to longcall functions since callee's return would skip the TOC restore in the caller. However, with PCREL we can now safely perform a sibling call to longcall functions. The problem with the current code in rs6000_sibcall_aix is that it asserts we do not have a longcall and fixing that, it generates a direct call to a PLT stub, when it should generate an indirect sibcall due to -fno-plt. The solution here is to check for a pcrel longcall and emit an indirect sibcall using an inline plt stub in that case. This passed bootstrap and regtesting on powerpc64le-linux with no regressions. Ok for trunk? This is marked as a GCC 11/12 regression. Ok for a GCC 11 backport after some burn-in on trunk? Peter gcc/ PR target/104894 * config/rs6000/rs6000.cc (rs6000_sibcall_aix): Handle pcrel sibcalls to longcall functions. gcc/testsuite/ PR target/104894 * gcc.target/powerpc/pr104894.c: New test. * gcc.target/powerpc/pr104894-2.c: New test. diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index cb18db06a2d..d38a1d61cfe 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -25659,11 +25659,21 @@ rs6000_sibcall_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) rtx r12 = NULL_RTX; rtx func_addr = func_desc; - gcc_assert (INTVAL (cookie) == 0); - if (global_tlsarg) tlsarg = global_tlsarg; + /* Handle longcall attributes. */ + if ((INTVAL (cookie) & CALL_LONG) != 0 + && GET_CODE (func_desc) == SYMBOL_REF) + { + /* Only PCREL can do a sibling call to a longcall function + because we don't need to restore the TOC register. */ + gcc_assert (rs6000_pcrel_p ()); + func_desc = rs6000_longcall_ref (func_desc, tlsarg); + } + else + gcc_assert (INTVAL (cookie) == 0); + /* For ELFv2, r12 and CTR need to hold the function address for an indirect call. */ if (GET_CODE (func_desc) != SYMBOL_REF && DEFAULT_ABI == ABI_ELFv2) diff --git a/gcc/testsuite/gcc.target/powerpc/pr104894.c b/gcc/testsuite/gcc.target/powerpc/pr104894.c new file mode 100644 index 00000000000..f46fe88168f --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr104894.c @@ -0,0 +1,20 @@ +/* PR target/104894 */ +/* { dg-require-effective-target powerpc_elfv2 } */ +/* { dg-require-effective-target power10_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power10 -fno-plt" } */ + +/* Verify we do not ICE on the following test case and that we emit an + indirect sibcall, with r12 and CTR containing the function address. */ + +void foo (void); + +void +bar (void) +{ + foo (); +} + +/* { dg-final { scan-assembler-times {\mmtctr 12\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mbctr\M} 1 } } */ +/* { dg-final { scan-assembler-not {\mbl\M} } } */ +/* { dg-final { scan-assembler-not {\mbctrl\M} } } */ diff --git a/gcc/testsuite/gcc.target/powerpc/pr104894-2.c b/gcc/testsuite/gcc.target/powerpc/pr104894-2.c new file mode 100644 index 00000000000..d1a011ef4d9 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr104894-2.c @@ -0,0 +1,22 @@ +/* PR target/104894 */ +/* { dg-require-effective-target powerpc_elfv2 } */ +/* { dg-require-effective-target power10_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power10 -fno-plt" } */ + +/* Verify we do not ICE on the following test case and that we emit one + indirect call and one indirect sibcall, with r12 and CTR containing + the function addresses. */ + +void foo (void); + +void +bar (void) +{ + foo (); + foo (); +} + +/* { dg-final { scan-assembler-times {\mmtctr 12\M} 2 } } */ +/* { dg-final { scan-assembler-times {\mbctrl\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mbctr\M} 1 } } */ +/* { dg-final { scan-assembler-not {\mbl\M} } } */