From patchwork Mon Jun 26 16:45:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Krebbel X-Patchwork-Id: 1800043 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=) Authentication-Results: legolas.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=dbD7D01t; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QqYcm2Z5Bz1yhT for ; Tue, 27 Jun 2023 02:45:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2456A3882031 for ; Mon, 26 Jun 2023 16:45:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2456A3882031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687797941; bh=ArpurbxzHGgx3zWVbEGza5nRaNgNWJHO4iAwBmBpU2E=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=dbD7D01tUX1Tvuvn2K8PyEihqhTzDo2oNa9dpxI159crkL458xRB4DnQyd9wYCBmS 27mfHw/8ANzmXz4hwgIIyA9AbnIJu5pkSa/wlpbWONDDWY2dpyBXZuIq44XTASAFxF Gc9rAT4joMxiX4DDdS5+K1YpKZUA86k5eywQZFcg= 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 EEDEC3857722 for ; Mon, 26 Jun 2023 16:45:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EEDEC3857722 Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35QGH3Pu013376 for ; Mon, 26 Jun 2023 16:45:18 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rfe298n95-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 26 Jun 2023 16:45:17 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35Q5GD25002662 for ; Mon, 26 Jun 2023 16:45:15 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3rdr4511pw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 26 Jun 2023 16:45:15 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35QGjCTp6292132 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 26 Jun 2023 16:45:12 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B74E020043 for ; Mon, 26 Jun 2023 16:45:12 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8226420040 for ; Mon, 26 Jun 2023 16:45:12 +0000 (GMT) Received: from li-ecc9ffcc-3485-11b2-a85c-e633c5126265.fritz.box (unknown [9.171.59.85]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Mon, 26 Jun 2023 16:45:12 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [Committed] IBM zSystems: Assume symbols without explicit alignment to be ok Date: Mon, 26 Jun 2023 18:45:12 +0200 Message-ID: <20230626164512.11512-1-krebbel@linux.ibm.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: OfhC9gFbN1ot9AQVSNT9-eIS2U5-cMdv X-Proofpoint-ORIG-GUID: OfhC9gFbN1ot9AQVSNT9-eIS2U5-cMdv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-26_14,2023-06-26_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 priorityscore=1501 malwarescore=0 suspectscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306260151 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, 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.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: Andreas Krebbel via Gcc-patches From: Andreas Krebbel Reply-To: Andreas Krebbel Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" A change we have committed back in 2015 relies on the backend requested ABI alignment to be applied to ALL symbols by the middle-end. However, this does not appear to be the case for external symbols. With this commit we assume all symbols without explicit alignment to be aligned according to the ABI. That's the behavior we had before. This fixes a performance regression caused by the 2015 patch. Since then the address of external char type symbols have been pushed to the literal pool, although it is safe to access them with larl (which requires symbols to reside at even addresses). Bootstrapped and regression tested on s390x. gcc/ * config/s390/s390.cc (s390_encode_section_info): Set SYMBOL_FLAG_SET_NOTALIGN2 only if the symbol has explicitely been misaligned. gcc/testsuite/ * gcc.target/s390/larl-1.c: New test. --- gcc/config/s390/s390.cc | 6 +++-- gcc/testsuite/gcc.target/s390/larl-1.c | 32 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/s390/larl-1.c diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc index 9284477396d..d9f10542473 100644 --- a/gcc/config/s390/s390.cc +++ b/gcc/config/s390/s390.cc @@ -13706,8 +13706,10 @@ s390_encode_section_info (tree decl, rtx rtl, int first) { /* Store the alignment to be able to check if we can use a larl/load-relative instruction. We only handle the cases - that can go wrong (i.e. no FUNC_DECLs). */ - if (DECL_ALIGN (decl) == 0 || DECL_ALIGN (decl) % 16) + that can go wrong (i.e. no FUNC_DECLs). + All symbols without an explicit alignment are assumed to be 2 + byte aligned as mandated by our ABI. */ + if (DECL_USER_ALIGN (decl) && DECL_ALIGN (decl) % 16) SYMBOL_FLAG_SET_NOTALIGN2 (XEXP (rtl, 0)); else if (DECL_ALIGN (decl) % 32) SYMBOL_FLAG_SET_NOTALIGN4 (XEXP (rtl, 0)); diff --git a/gcc/testsuite/gcc.target/s390/larl-1.c b/gcc/testsuite/gcc.target/s390/larl-1.c new file mode 100644 index 00000000000..5ef2ef63f82 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/larl-1.c @@ -0,0 +1,32 @@ +/* Check if load-address-relative instructions are created */ + +/* { dg-do compile { target { s390*-*-* } } } */ +/* { dg-options "-O2 -march=z10 -mzarch -fno-section-anchors" } */ + +/* An explicitely misaligned symbol. This symbol is NOT aligned as + mandated by our ABI. However, the back-end needs to handle that in + order to make things like __attribute__((packed)) work. The symbol + address is expected to be loaded from literal pool. */ +/* { dg-final { scan-assembler "lgrl\t%r2," { target { lp64 } } } } */ +/* { dg-final { scan-assembler "lrl\t%r2," { target { ! lp64 } } } } */ +extern char align1 __attribute__((aligned(1))); + +/* { dg-final { scan-assembler "larl\t%r2,align2" } } */ +extern char align2 __attribute__((aligned(2))); + +/* { dg-final { scan-assembler "larl\t%r2,align4" } } */ +extern char align4 __attribute__((aligned(4))); + +/* An external char symbol without explicit alignment has a DECL_ALIGN + of just 8. In contrast to local definitions DATA_ABI_ALIGNMENT is + NOT applied to DECL_ALIGN in that case. Make sure the backend + still assumes this symbol to be aligned according to ABI + requirements. */ +/* { dg-final { scan-assembler "larl\t%r2,align_default" } } */ +extern char align_default; + +char * foo1 () { return &align1; } +char * foo2 () { return &align2; } +char * foo3 () { return &align4; } +char * foo4 () { return &align_default; } +