From patchwork Tue Jul 19 08:30:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 50 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a98:d5ce:0:b0:178:cc93:bf7d with SMTP id g14csp2307083eik; Tue, 19 Jul 2022 01:32:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v1D38vVAYmjoZgp2e3rRwsoYJpXq3zmFyrGa4cDdfcb8pjcQO0pBIQR6ES/587HoEQwHlK X-Received: by 2002:a17:907:1c8f:b0:6e8:f898:63bb with SMTP id nb15-20020a1709071c8f00b006e8f89863bbmr30135612ejc.721.1658219532954; Tue, 19 Jul 2022 01:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658219532; cv=none; d=google.com; s=arc-20160816; b=xChos1Xid6uiQk0istyoikVZMpyX1U5VMQ/Uk565hs18/mlg0hHt7mtcuAm+1Az1pT DxPJP6vjVMs2wuOHSyFPu5a0rWo/1b80YPFJWAMi1ufan+RbjySL82nQrbpSaqC/u4AE fNquObhiqyYqEt/HBJ5kKubyWullpe+f7YFzvF/dpALoA7BbRkc+fnB2heqcRWeeS6dl +qr+NOab1iW3IqRV/0N3X95S0o9YGtDiv24CSFxaevNxTAJpk8ZXtDVq1LRSJGTnhf+8 K8Q2ZFY2xC81iZsSHY7mQYUxqJplJvQdccy4v4mKXwk4kg4cxXzPsg/ki9j3Okqfs1VV 7Mdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=ux9vfUSniXNf/BUEyfbmJTC3Ff/BQiMTnoseSnsm3rk=; b=C+tiLZAYanBupMnuTtRTDFTDArF1RueWuVaaXXVHoDJXyaRswNUNruek3iAx0vqXpj uVyj6RdpjMPOLTlpKE9GGTs170WOkqPWv85X+TCfpoxS1H6q99FecZjN1kg/Uev0z6AD 3AnaRzJN4MybaPknBZ1t0o//RfQwRldP5nx3wZxegwOoTdQS8a8rz3TfVC2PvurfQWim BNJ8mEKxNCTqyQoAmXPKTjxnzwSPOQv80ENdB+tb7scZM4Oxkn5FBIUJ5UrKt2eAr0e5 zeuqE/kGFpH72c4sMewwnd+W+DzqpTY0ggKRu//rwfdEPpO7ZDGUWTlyf/pms28DExGi GCpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ICYZYmVo; 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 d4-20020a170906344400b0072b83c76e0esi15505980ejb.252.2022.07.19.01.32.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 01:32:12 -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=ICYZYmVo; 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 712A9385AE43 for ; Tue, 19 Jul 2022 08:32:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 712A9385AE43 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658219530; bh=ux9vfUSniXNf/BUEyfbmJTC3Ff/BQiMTnoseSnsm3rk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ICYZYmVoWG6j6enM673bwpa8k9G5022QNCQwyZzLq8UtnUdvFP9UiFdmjGQYNJ0l6 GSAkH55AsM9uEBgRumzKRjjAlDHXNfhk15cgSOryUg4J7nW+DH483sy+Rggs0jMm/O bjBZa7yjVBF+SWHWIAZfP/A7M/r3PLEV8kZ31goE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id BC04F3857375 for ; Tue, 19 Jul 2022 08:30:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BC04F3857375 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id DBB142231B for ; Tue, 19 Jul 2022 08:30:49 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id D6EE82C141 for ; Tue, 19 Jul 2022 08:30:49 +0000 (UTC) Date: Tue, 19 Jul 2022 08:30:49 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/106331 - fix mem attributes for string op arguments User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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: Richard Biener via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20220719083210.712A9385AE43@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-LABELS: =?utf-8?b?IlxcSW1wb3J0YW50Ig==?= X-GMAIL-THRID: =?utf-8?q?1738769204984085035?= X-GMAIL-MSGID: =?utf-8?q?1738769204984085035?= get_memory_rtx tries hard to come up with a MEM_EXPR to record in the memory attributes but in the last fallback fails to properly account for an unknown offset and thus, as visible in this testcase, incorrect alignment computed from set_mem_attributes. The following rectifies both parts. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. PR middle-end/106331 * builtins.cc (get_memory_rtx): Compute alignment from the original address and set MEM_OFFSET to unknown when we create a MEM_EXPR from the base object of the address. * gfortran.dg/pr106331.f90: New testcase. --- gcc/builtins.cc | 13 +++++++++---- gcc/testsuite/gfortran.dg/pr106331.f90 | 7 +++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr106331.f90 diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 35b9197945f..bc05a40bfe7 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -1360,7 +1360,7 @@ expand_builtin_prefetch (tree exp) rtx get_memory_rtx (tree exp, tree len) { - tree orig_exp = exp; + tree orig_exp = exp, base; rtx addr, mem; /* When EXP is not resolved SAVE_EXPR, MEM_ATTRS can be still derived @@ -1391,10 +1391,11 @@ get_memory_rtx (tree exp, tree len) if (is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0))) set_mem_attributes (mem, exp, 0); else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR - && (exp = get_base_address (TREE_OPERAND (TREE_OPERAND (exp, 0), - 0)))) + && (base = get_base_address (TREE_OPERAND (TREE_OPERAND (exp, 0), + 0)))) { - exp = build_fold_addr_expr (exp); + unsigned int align = get_pointer_alignment (TREE_OPERAND (exp, 0)); + exp = build_fold_addr_expr (base); exp = fold_build2 (MEM_REF, build_array_type (char_type_node, build_range_type (sizetype, @@ -1402,6 +1403,10 @@ get_memory_rtx (tree exp, tree len) NULL)), exp, build_int_cst (ptr_type_node, 0)); set_mem_attributes (mem, exp, 0); + /* Since we stripped parts make sure the offset is unknown and the + alignment is computed from the original address. */ + clear_mem_offset (mem); + set_mem_align (mem, align); } set_mem_alias_set (mem, 0); return mem; diff --git a/gcc/testsuite/gfortran.dg/pr106331.f90 b/gcc/testsuite/gfortran.dg/pr106331.f90 new file mode 100644 index 00000000000..3873863be48 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr106331.f90 @@ -0,0 +1,7 @@ +! { dg-do run } +! { dg-options "-Og" } + +PROGRAM main + CHARACTER(LEN=24) :: a(2) + a = '' +END PROGRAM