From patchwork Fri Jun 2 07:35:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 70497 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DCF433856DD4 for ; Fri, 2 Jun 2023 07:36:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DCF433856DD4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685691398; bh=jkrVZg3aVxKlhz5tmEJo4Z0tXxnb0XGZOaIKfN6zMQI=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=g2n0yprmaiqvZX/thfePqpdWjVt8aIR+N232d1ZmmVaRn1+6AYKk4vnIWMWI3WX78 JYzBwvPddOHkvDtjuyoy4RqkEYzOAIKZPbLbinqo8aq7prPu5ROSQ2qt/5nUl0Lppr vXTweOql+c+b1tSx4r9WJHmp4dTI2/YvTFXKFQOM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 7D7833858C53 for ; Fri, 2 Jun 2023 07:36:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7D7833858C53 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 351M8FgD026967 for ; Fri, 2 Jun 2023 00:36:09 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3qy3uyhpe7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 02 Jun 2023 00:36:09 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 2 Jun 2023 00:36:07 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 2 Jun 2023 00:36:07 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 1D88D3F7041; Fri, 2 Jun 2023 00:36:07 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] rtl-optimization: [PR102733] DSE removing address which only differ by address space. Date: Fri, 2 Jun 2023 00:35:59 -0700 Message-ID: <20230602073559.2690527-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: cDLUSh4MQyIIyBNWPQWYstzQxvWOiAgy X-Proofpoint-ORIG-GUID: cDLUSh4MQyIIyBNWPQWYstzQxvWOiAgy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-02_04,2023-05-31_03,2023-05-22_02 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The problem here is DSE was not taking into account the address space which meant if you had two addresses say `fs:0` and `gs:0` (on x86_64), DSE would think they were the same and remove the first store. This fixes that issue by adding a check for the address space too. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR rtl-optimization/102733 gcc/ChangeLog: * dse.cc (store_info): Add addrspace field. (record_store): Record the address space and check to make sure they are the same. gcc/testsuite/ChangeLog: * gcc.target/i386/addr-space-6.c: New test. --- gcc/dse.cc | 9 ++++++++- gcc/testsuite/gcc.target/i386/addr-space-6.c | 21 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/addr-space-6.c diff --git a/gcc/dse.cc b/gcc/dse.cc index 802b949cfb2..8b07be17674 100644 --- a/gcc/dse.cc +++ b/gcc/dse.cc @@ -251,6 +251,9 @@ public: and known (rather than -1). */ poly_int64 width; + /* The address space that the memory reference uses. */ + unsigned char addrspace; + union { /* A bitmask as wide as the number of bytes in the word that @@ -1524,6 +1527,7 @@ record_store (rtx body, bb_info_t bb_info) ptr = active_local_stores; last = NULL; redundant_reason = NULL; + unsigned char addrspace = MEM_ADDR_SPACE (mem); mem = canon_rtx (mem); if (group_id < 0) @@ -1548,7 +1552,9 @@ record_store (rtx body, bb_info_t bb_info) while (!s_info->is_set) s_info = s_info->next; - if (s_info->group_id == group_id && s_info->cse_base == base) + if (s_info->group_id == group_id + && s_info->cse_base == base + && s_info->addrspace == addrspace) { HOST_WIDE_INT i; if (dump_file && (dump_flags & TDF_DETAILS)) @@ -1688,6 +1694,7 @@ record_store (rtx body, bb_info_t bb_info) store_info->rhs = rhs; store_info->const_rhs = const_rhs; store_info->redundant_reason = redundant_reason; + store_info->addrspace = addrspace; /* If this is a clobber, we return 0. We will only be able to delete this insn if there is only one store USED store, but we diff --git a/gcc/testsuite/gcc.target/i386/addr-space-6.c b/gcc/testsuite/gcc.target/i386/addr-space-6.c new file mode 100644 index 00000000000..82eca4d7e0c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/addr-space-6.c @@ -0,0 +1,21 @@ +/* PR rtl-optimization/102733 */ +/* { dg-do compile } */ +/* { dg-options "-O1" } */ + +/* DSE was removing a store to fs:0 (correctly) + and gs:0 (incorrectly) as DSE didn't take into + account the address space was different. */ + +void test_null_store (void) +{ + int __seg_fs *fs = (int __seg_fs *)0; + *fs = 1; + + int __seg_gs *gs = (int __seg_gs *)0; + *gs = 2; + *fs = 3; +} + +/* { dg-final { scan-assembler-times "movl\t" 2 } } */ +/* { dg-final { scan-assembler "gs:" } } */ +/* { dg-final { scan-assembler "fs:" } } */