From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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 (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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=ArpurbxzHGgx3zWVbEGza5nRaNgNWJHO4iAwBmBpU2E=; b=CY4HVNfZGqTg1mSls8qDaCZ5SokO6sJrNtzt9K8Y3Lnt+lt6usgFiJ0YEw6+xLlpL8gX h+wVxyHKQImquPWiIksx/9zCeFK9NVk4CigmMqB7I4tqdmGpxoaYOZFcKDiS6sNzzAgV uhx2p5EDcgOPd20pdL5MvNTJ9MURNalhy2jj+z66G0jtrgOM1SlVDxwkBDPEmLw46vtX FOhHAyYHab02hcqz/AvyF/LMfnQl6EAT2bse+RpgPeb+WVF3WoVfh3aze4eCXekmGSK9 CDWRQDL2NuJ28JqCK3Vu7YBIDI2ObJHSHFJQwjO1WIF0f7GI+VQQb9C5g9yeVMoH8W+v xg== 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) From: Andreas Krebbel 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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; } + -- 2.41.0