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: 102342 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp854192vqr; Fri, 2 Jun 2023 00:36:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ70ZUlR1LZ2HMbcsZx+4GZFQEhlUrPMVwVfLqVvD247X4qlKR5goK7tr/4YepOiQ7a6CWJ+ X-Received: by 2002:a17:906:4fd0:b0:965:d17b:26d with SMTP id i16-20020a1709064fd000b00965d17b026dmr12269383ejw.35.1685691415459; Fri, 02 Jun 2023 00:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685691415; cv=none; d=google.com; s=arc-20160816; b=d8NNdAuMCsK9N8tBzZQsOXFV66sRBafbJMEJGr6gsOWk38RxrvkofoYlX1VV1KCwcL kEJjtwL1aafiwNmrVybEpJbeHVuiEwigbCXXRAkdZNdWbvBaMb+6+n+rftbLb6RZ+lUM cBrCxwlLh17/txFI81tPz98LPtYHmuJ4Ch9h8cA7f5DnASIqTrEvQdhmujjjT8KR7njZ EYcPlXsnRxg2QZ8AKv0kEuHKdmLkWzAfIHaZgQl++HZDRilJIOLQdqqpu0AvehlZ8FFa r3Y1dE4VwTwYAQhWwFh5LzIxsFgjhrInmJIv/XCCqMv7zPVBtvojRljwz3U+k4dpfWQf PIgQ== 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 :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=jkrVZg3aVxKlhz5tmEJo4Z0tXxnb0XGZOaIKfN6zMQI=; b=uiW9a7FtEu6Gvtt+fiUYZKv/C3GeeA0f9LId+TaL0RpSQbdT0Luj2ng7ECdzvWC4YC ZIxQCSbZNCGK3GVrh/1vtlgObx4rhtcKvLQ5jE8MRoIWf3WlszVADUeEcPIMn+BB48Ci uxdXou9NL5n570Yz/HJ3VVRYVQBYbjzBboJ3mX+Arq+K8kZt1yt3kyB0QySHJdYnhaJT 1LrbGjOyQpVihPpZrB9PjAovzPBoByNKtRR01pdbokK+tWa2QRZ9kw8P/L75veUwIT9Y w6EQsJDYr9ByAmVFob1u74fBDKvH4lKbWhmG2iiEErHd+bz8Y+pbxSCmap0TphjsD9DJ ekIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JDPPCntJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id mf18-20020a1709071a5200b009575f5ec9c5si452458ejc.314.2023.06.02.00.36.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 00:36:55 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JDPPCntJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 68763385700C for ; Fri, 2 Jun 2023 07:36:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68763385700C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685691414; bh=jkrVZg3aVxKlhz5tmEJo4Z0tXxnb0XGZOaIKfN6zMQI=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=JDPPCntJ8VGi48gF5uVUoA/t7CHzUvHtXftdwCohdLMVcCJLXmc8Qo/afK1mjCThG nWBiPSswBFVTDl/Joai2P11EktIcC2D36iF+IVRlLodwbhBKeWDf9qlmuCNSxwO1lj UOdpqw1gcRdzM4oRUwH5JYbaF9+8ngFwiS/Dc15I= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767575561241847103?= X-GMAIL-MSGID: =?utf-8?q?1767575561241847103?= 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:" } } */