From patchwork Thu Apr 13 16:00:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 83027 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1140747vqo; Thu, 13 Apr 2023 09:00:52 -0700 (PDT) X-Google-Smtp-Source: AKy350Z8E2cX8poH6O/BW9LSW6NqHe95lBB5j/0X8Fjr5bcGjPtGtHfKNOsl5uWngUV4qRVNuAI+ X-Received: by 2002:a17:906:1849:b0:94a:959f:8089 with SMTP id w9-20020a170906184900b0094a959f8089mr3160223eje.50.1681401652454; Thu, 13 Apr 2023 09:00:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681401652; cv=none; d=google.com; s=arc-20160816; b=jtIR0w5qGAw+i6caHCNZu8FjvEH/yw3RlvdmdPbWGTj6aEoe6P2wmic0CEPvEQJVgU yLpfGJVG5s2tcRLAEuUcna8IAVAc/WfsdjbgozgWhokpPOng9FoBFFnuTRjHteyo6QOV hTRmZeesb4uqx3qz7HVURoNCArEBMzOuN2dHiwBRBH5z7sP4Pdd5ProxR6zZ8lDRty8V qe/Uifd1dPMRgB5EwJMU0T/vYYpcuRnm7kwHpZ35f4/3KXfB2GtntWfunxhyJGSeeGDZ cux1fn6oNWlB3jOVgyVqJZRAr+uSk0MdPmTwmOvOUOTF3fxCxrSAs4YcKgk4TjnGI8dq gkLQ== 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 :user-agent:message-id:date:subject:cc:mail-followup-to:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=oPe+JIs8ZDK91KeLi3B7mIi3nkI/WUf4GEq6xKgvYqY=; b=A3mnO1x9GvDxFt6029C0erQ0ErrGikcWoBAMn8Jq/1ieIVXk2Fc6y8Lj3fGZeQpHYW d3IWni22vUFZqCUi/bZCq/QMJVFsg49F/hr2oD+XPOmQcx32Q3nokSwxt/DQ99wW0452 NkzRzL4qI2zgTYBUrw8deJgqKyNBqHGtG4otmsoAU0d5JWufG8kcdyXdTZfXCT2ORlpS MKma/d4dmEEiqV7hDA6+i7CCxSCBGTIY/MkUE5zJ3SkGHnvv+pPN7OORviDDLda+flOa NmCxn0dWOSWZhcmz2ZbN0p11U29Su68X7P+NXgaTJ9kl8TnPk5nH3pjKbsL686D0oEdk ncxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=icStIo69; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id q17-20020a1709063d5100b0094a4a9913e7si1931797ejf.754.2023.04.13.09.00.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 09:00:52 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=icStIo69; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 0BC683858C00 for ; Thu, 13 Apr 2023 16:00:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BC683858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681401651; bh=oPe+JIs8ZDK91KeLi3B7mIi3nkI/WUf4GEq6xKgvYqY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=icStIo692uewMusQFNXH4NsWAxaRRGWe09MsBie0eeFBoyax9x3quCwuhVupJf9B/ irdrAL38eSQEdBvTC+RSNxw8bfAtO8Bz2kZM22EWePZpzopwjqLjZ4PitdVqGYyZJ1 MeqaxkHg+MdJpVamjX023oMMoIrcFBUizh+ONPLE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 712173858D20 for ; Thu, 13 Apr 2023 16:00:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 712173858D20 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 906E2D75; Thu, 13 Apr 2023 09:00:51 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9D4043F6C4; Thu, 13 Apr 2023 09:00:06 -0700 (PDT) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, jakub@redhat.com, richard.sandiford@arm.com Cc: jakub@redhat.com Subject: [PATCH] aarch64: Don't trust TYPE_ALIGN for pointers [PR108910] Date: Thu, 13 Apr 2023 17:00:05 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-31.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, 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: Richard Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford 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?1763077418932667724?= X-GMAIL-MSGID: =?utf-8?q?1763077418932667724?= The aarch64 PCS rules ignore user alignment for scalars and vectors and use the "natural" alignment of the type. GCC tried to calculate that natural alignment using: TYPE_ALIGN (TYPE_MAIN_VARIANT (type)) But as discussed in the PR, it's possible that the main variant of a pointer type is an overaligned type (although that's usually accidental). This isn't known to be a problem for other types, so this patch changes the bare minimum. It might be that we need to ignore TYPE_ALIGN in other cases too. Tested on aarch64-linux-gnu & pushed to trunk so far. Will backport to GCC 12 soon. Richard gcc/ PR target/108910 * config/aarch64/aarch64.cc (aarch64_function_arg_alignment): Do not trust TYPE_ALIGN for pointer types; use POINTER_SIZE instead. gcc/testsuite/ PR target/108910 * gcc.dg/torture/pr108910.c: New test. --- gcc/config/aarch64/aarch64.cc | 15 ++++++++++++++- gcc/testsuite/gcc.dg/torture/pr108910.c | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr108910.c diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 42617ced73a..f4ef22ce02f 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -7484,7 +7484,20 @@ aarch64_function_arg_alignment (machine_mode mode, const_tree type, gcc_assert (TYPE_MODE (type) == mode); if (!AGGREGATE_TYPE_P (type)) - return TYPE_ALIGN (TYPE_MAIN_VARIANT (type)); + { + /* The ABI alignment is the natural alignment of the type, without + any attributes applied. Normally this is the alignment of the + TYPE_MAIN_VARIANT, but not always; see PR108910 for a counterexample. + For now we just handle the known exceptions explicitly. */ + type = TYPE_MAIN_VARIANT (type); + if (POINTER_TYPE_P (type)) + { + gcc_assert (known_eq (POINTER_SIZE, GET_MODE_BITSIZE (mode))); + return POINTER_SIZE; + } + gcc_assert (!TYPE_USER_ALIGN (type)); + return TYPE_ALIGN (type); + } if (TREE_CODE (type) == ARRAY_TYPE) return TYPE_ALIGN (TREE_TYPE (type)); diff --git a/gcc/testsuite/gcc.dg/torture/pr108910.c b/gcc/testsuite/gcc.dg/torture/pr108910.c new file mode 100644 index 00000000000..59735488c2e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr108910.c @@ -0,0 +1,8 @@ +extern void foo (float, float *, float *); + +void +bar (void *p) +{ + float *__attribute__((aligned (64))) q = __builtin_assume_aligned (p, 64); + foo (0.0f, q, q); +}