From patchwork Thu Jul 2 13:22:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xiezhiheng X-Patchwork-Id: 1321424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com 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 ozlabs.org (Postfix) with ESMTPS id 49yJfq3Pv8z9sDX for ; Thu, 2 Jul 2020 23:22:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DAADE3861969; Thu, 2 Jul 2020 13:22:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from huawei.com (szxga02-in.huawei.com [45.249.212.188]) by sourceware.org (Postfix) with ESMTPS id B4072386192E for ; Thu, 2 Jul 2020 13:22:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B4072386192E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xiezhiheng@huawei.com Received: from DGGEMM406-HUB.china.huawei.com (unknown [172.30.72.57]) by Forcepoint Email with ESMTP id D7354CB8CBB87CB37A99 for ; Thu, 2 Jul 2020 21:22:17 +0800 (CST) Received: from dggeme713-chm.china.huawei.com (10.1.199.109) by DGGEMM406-HUB.china.huawei.com (10.3.20.214) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 2 Jul 2020 21:22:17 +0800 Received: from dggema767-chm.china.huawei.com (10.1.198.209) by dggeme713-chm.china.huawei.com (10.1.199.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1913.5; Thu, 2 Jul 2020 21:22:17 +0800 Received: from dggema767-chm.china.huawei.com ([10.9.48.82]) by dggema767-chm.china.huawei.com ([10.9.48.82]) with mapi id 15.01.1913.007; Thu, 2 Jul 2020 21:22:17 +0800 From: xiezhiheng To: "gcc-patches@gcc.gnu.org" Subject: [PATCH PR94442] [AArch64] Redundant ldp/stp instructions emitted at -O3 Thread-Topic: [PATCH PR94442] [AArch64] Redundant ldp/stp instructions emitted at -O3 Thread-Index: AdZQc3HuQshNoXkyQhKLxJ4muvJVsw== Date: Thu, 2 Jul 2020 13:22:17 +0000 Message-ID: <014c7f5ef7874db4ae98470c298b1f9b@huawei.com> Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.174.187.14] MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This is a fix for pr94442. I modify get_inner_reference to handle the case for MEM[ptr, off]. I extract the "off" and add it to the recorded offset, then I build a MEM[ptr, 0] and return it later. I add an argument "include_memref_p" to control whether to go into MEM_REF, because without it will cause the test case "Warray-bounds-46.c" to fail in regression. It because function set_base_and_offset in gimple-ssa-warn-restrict.c base = get_inner_reference (expr, &bitsize, &bitpos, &var_off, &mode, &sign, &reverse, &vol); ... ... if (TREE_CODE (base) == MEM_REF) { tree memrefoff = fold_convert (ptrdiff_type_node, TREE_OPERAND (base, 1)); extend_offset_range (memrefoff); base = TREE_OPERAND (base, 0); if (refoff != HOST_WIDE_INT_MIN && TREE_CODE (expr) == COMPONENT_REF) { /* Bump up the offset of the referenced subobject to reflect the offset to the enclosing object. For example, so that in struct S { char a, b[3]; } s[2]; strcpy (s[1].b, "1234"); REFOFF is set to s[1].b - (char*)s. */ offset_int off = tree_to_shwi (memrefoff); refoff += off; } if (!integer_zerop (memrefoff)) <================= /* A non-zero offset into an array of struct with flexible array members implies that the array is empty because there is no way to initialize such a member when it belongs to an array. This must be some sort of a bug. */ refsize = 0; } needs MEM_REF offset to judge whether refsize should be set to zero. But I fold the offset into bitpos and the offset will always be zero. Suggestion? diff --git a/gcc/expr.c b/gcc/expr.c index 3c68b0d754c..8cc18449a0c 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -7362,7 +7362,8 @@ tree get_inner_reference (tree exp, poly_int64_pod *pbitsize, poly_int64_pod *pbitpos, tree *poffset, machine_mode *pmode, int *punsignedp, - int *preversep, int *pvolatilep) + int *preversep, int *pvolatilep, + bool include_memref_p) { tree size_tree = 0; machine_mode mode = VOIDmode; @@ -7509,6 +7510,21 @@ get_inner_reference (tree exp, poly_int64_pod *pbitsize, } exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); } + else if (include_memref_p + && TREE_CODE (TREE_OPERAND (exp, 0)) == SSA_NAME) + { + tree off = TREE_OPERAND (exp, 1); + if (!integer_zerop (off)) + { + poly_offset_int boff = mem_ref_offset (exp); + boff <<= LOG2_BITS_PER_UNIT; + bit_offset += boff; + + exp = build2 (MEM_REF, TREE_TYPE (exp), + TREE_OPERAND (exp, 0), + build_int_cst (TREE_TYPE (off), 0)); + } + } goto done; default: @@ -10786,7 +10802,7 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode, int reversep, volatilep = 0, must_force_mem; tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1, - &unsignedp, &reversep, &volatilep); + &unsignedp, &reversep, &volatilep, true); rtx orig_op0, memloc; bool clear_mem_expr = false; diff --git a/gcc/tree.h b/gcc/tree.h index a74872f5f3e..7df0d15f7f9 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -6139,7 +6139,8 @@ extern bool complete_ctor_at_level_p (const_tree, HOST_WIDE_INT, const_tree); look for the ultimate containing object, which is returned and specify the access position and size. */ extern tree get_inner_reference (tree, poly_int64_pod *, poly_int64_pod *, - tree *, machine_mode *, int *, int *, int *); + tree *, machine_mode *, int *, int *, int *, + bool = false); extern tree build_personality_function (const char *);