From patchwork Fri Jul 29 13:52:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard Earnshaw (lists)" X-Patchwork-Id: 308 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp825533pxt; Fri, 29 Jul 2022 06:53:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sumVhsXTFkLpArLxifwB2O/lxqyQJfAaKoQ0pi/zXwQkSFiZh2j6Ba3oZ1XEt370R51HLo X-Received: by 2002:a05:6402:44d:b0:43b:e6e2:c98 with SMTP id p13-20020a056402044d00b0043be6e20c98mr3636499edw.323.1659102791247; Fri, 29 Jul 2022 06:53:11 -0700 (PDT) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hd7-20020a170907968700b0072a4249e9b5si4581020ejc.17.2022.07.29.06.53.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 06:53:11 -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=DZfz1K54; arc=fail (signature failed); 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 AC21F3857BAB for ; Fri, 29 Jul 2022 13:53:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AC21F3857BAB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1659102789; bh=C3pXeMjliM9gSjMdaBmr/Sma+GB4JmaDZectO1im4E8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DZfz1K543OsDSt0k+2i8KhtbJGdJksgUR4a+Uqh2tB0Vt8I2bN4hToDBw8yXp4gno zmliZiQHj7FYuF/HasX0b9KsGgG+5s3xCDfCA3eb8unZOGXIWD/raUHRAp/4LNiDfa kbshjK5h8Maae47olGCzfnPQ/XPFA8IvgunPqxj4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70055.outbound.protection.outlook.com [40.107.7.55]) by sourceware.org (Postfix) with ESMTPS id EA6DA3858429 for ; Fri, 29 Jul 2022 13:52:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EA6DA3858429 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=P3Dh/KC4UwxWyk87HjeFk6MWKbeb8wLvknxZFelgnrh8gU5gsadeD1SRiemWqovPJERYSqPKIRUYuKHgByRsE5FUPPc6S24hu30KQRjeCvgKlAHR0UKGQ07wnzfspOE4NlFygqxjj/o5n4jURlGvFcJ7oGCp98AsyxLFKmf+mNOg+XI+lVHaQE3xWKlqI9ncNjsE77qc4KUAL6GmwZY2xO96i6GeRqqo3Ry67R8d1RN4LXlNts/7C+pGPiHxUyKyWnJNpWvpsaKQUL+7KXaqduCynGig/EcL/OuInuCbxRXMEFIILgR+/0NgQKeKJWlKv0erPdJHQSzDrGlKyM+DTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=C3pXeMjliM9gSjMdaBmr/Sma+GB4JmaDZectO1im4E8=; b=n6LDoohIe4H1amwLyOaLBEGzjUWXL/qdnXLO380V6NjPwYv77PhL3rdIjOMaMMtwI/Sj/ImgvfWh02wiXaqUw/9C0hE2J9OFtFCFfIG1sCRxkVc8YbQcX/STuERRCHlSwSc3qRbbwnONbwjd/bqdZjXSgl5ugVrQCEcHSrIwpUH1Wezx6Uj8nJ/dwKSXXYRrbFeOvhB+U2TEqPmPuiO4c2+786OSfrj7KAbXlyKe6ryJrSmtHoxHx9zfTQV2PMzMGNTTLoa2JYvWdKTGxR5IO7g/ZYMC1icFRCvWTq5+v21ZpT5a80odlPp3w45qpIZkGaeKO0RKWMD48NnBI4TMkg== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from AS9P194CA0030.EURP194.PROD.OUTLOOK.COM (2603:10a6:20b:46d::26) by DBAPR08MB5640.eurprd08.prod.outlook.com (2603:10a6:10:1a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.11; Fri, 29 Jul 2022 13:52:21 +0000 Received: from AM5EUR03FT045.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:46d:cafe::cd) by AS9P194CA0030.outlook.office365.com (2603:10a6:20b:46d::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.10 via Frontend Transport; Fri, 29 Jul 2022 13:52:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT045.mail.protection.outlook.com (10.152.17.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.12 via Frontend Transport; Fri, 29 Jul 2022 13:52:21 +0000 Received: ("Tessian outbound fa99bf31ee7d:v123"); Fri, 29 Jul 2022 13:52:20 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: dc5c815d4ff01215 X-CR-MTA-TID: 64aa7808 Received: from 6a5b088dabdc.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 55D90020-36EB-4779-AF7B-2FDB4DCA3DD1.1; Fri, 29 Jul 2022 13:52:09 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 6a5b088dabdc.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 29 Jul 2022 13:52:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I+MJqrvurt//I+MplZUla75Im/fb1RcjmeAPH1137Jdo4UyikZ4je8UM/shWbaJuoZg9DPmXleURdCXskjvvyv2dPOjkb+i3q2cAHzLuto93MY7+YTV0nGU/crbIaPxDviKTAgnHp5wxx56RLafLidnWmtxQawqvzmht6OaKnMMM2zJCJ5/hINJoapBLYyNakEPzMGo5pYQ4vjmEyC4iSULlZDIt5lTdls98S+Gfay8ZAVD7NFi5iKVCGHVSuklySC/BnqLCHexGTeLwD7D2bJ6gH1puEfeAi9G2UTD6GQR5hNRL6y+Hq7tR0HKOIY2w5gcnZuScm/jD4m0wJp7W5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=C3pXeMjliM9gSjMdaBmr/Sma+GB4JmaDZectO1im4E8=; b=G2ZsfDFozidLuYqmDGyqxBrPfDAo5X0/XcZXZVoCeN6TYJl8cBYcFi+JGp8pyjVOwhV9/9PNuILlzRmC5xo+8axR8PkSSg4LbrztjCYDmiYu139aoEr80ohb95WAfVsCeS5cC1LKs1hjupvsWLwEhzaxYdeKJ+9wA9aaGYmvic5ZYWVRETO6Q0sEuTzFDKD6nrMetF1FW2R77+L9ZdJ+L6sxQHTDRdWFii2uU119CnoxwPedtmDjNoqKmg9mj8/kMOz1CDRqwgCWOiqr7KVSNQx1pxxg8MXDsu4oWQWKBx6SzuTD2t6d4Y65WV3oegTOO78O7DbRYOlnY6zyoHqIaw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from DB9PR08MB7115.eurprd08.prod.outlook.com (2603:10a6:10:2c8::5) by PAXPR08MB7419.eurprd08.prod.outlook.com (2603:10a6:102:2ba::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.10; Fri, 29 Jul 2022 13:52:06 +0000 Received: from DB9PR08MB7115.eurprd08.prod.outlook.com ([fe80::583a:e544:1057:9d7b]) by DB9PR08MB7115.eurprd08.prod.outlook.com ([fe80::583a:e544:1057:9d7b%8]) with mapi id 15.20.5482.010; Fri, 29 Jul 2022 13:52:06 +0000 Message-ID: Date: Fri, 29 Jul 2022 14:52:03 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-GB To: "gcc-patches@gcc.gnu.org" , Richard Biener Subject: [PATCH v2] cselib: add function to check if SET is redundant [PR106187] Organization: Arm Ltd X-ClientProxiedBy: LO4P123CA0422.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18b::13) To DB9PR08MB7115.eurprd08.prod.outlook.com (2603:10a6:10:2c8::5) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: b72a0797-882e-4a66-faf3-08da71698f01 X-MS-TrafficTypeDiagnostic: PAXPR08MB7419:EE_|AM5EUR03FT045:EE_|DBAPR08MB5640:EE_ x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Wuy1xAyV4K3diHvGKHDrvl9pOuaC+zYGiqpjCpjgdAxnQj/ANch9FzeDXN/PA0JfgipEoclbqN2s+YJ1zrmCGRbl6IVrrtHMSzz6lxFMhP91O3JJCxnDpXvdZ3Z5zQ9o0LD2Jm3X9EiU3hV0kzQbbLys4laZkRmsR/ByjwbGO26izvd4Lau7UxwxHwz3RFkY+YoQ4CERtvw00BPqBsfnOwvodtTw+HYxbRMdhBlXDiff2eHU9diFVTOpUqDsk9w4f+DXJaAXFHfujCVuOeAsSU44EHUcdUyE5f+eSw3d0eZ/dbc2EtKXhBnQ7Jb2b+cUN3wMI8HC2/1w9bPlOEyuneTuLcIFcA2iOkuVHpPu3VKTPudwNSQTTq8tt4KpHDLEiozbm0aPmdlKPtFIxSPp/vUyU3axA7OjhcfF1mxeBXx3m2zvKObS3viNQOuoZ1tLF1yUyZFhbPzIttSFWGwqx4KzZZEvKTMDGJJLNaFZumtYFs23o4L3aORfJ6YpBCspZ+694BzHVq0mB9EmDm7Nq7R4+d+AjIqKEoskswWTlCjxnt2HN1hchnM5qr0Gh7EiGBdKD1XFIO2TIuVGuVMNbh9R788jJBCKe+9HY+Q1A8k42z5BgIZKO1RDs3lClIXvVcoHD4wmjbOS6q2pl8qMTN8TAwlqHT5xqwxHYSJJzD6fEPN6avM7pytHxuj7dc+SLTVM4MmReLS5bhcBsi5vbod5eDZI1DClaWd/17Sq6vfMdqW6BWh/pJh8Ohyt41lLUsxN/AJ9nyVNFM7DLxL+eaKS2yH8QmAmN1jjYtU1De9dqf5YUEmLRenj+dbLUaucZgKZI5nKoPPKC2wtjMgmuw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB7115.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(39860400002)(366004)(396003)(376002)(136003)(346002)(110136005)(316002)(186003)(2616005)(83380400001)(6486002)(6666004)(41300700001)(478600001)(6512007)(26005)(36916002)(33964004)(6506007)(38100700002)(2906002)(31686004)(8936002)(235185007)(5660300002)(8676002)(36756003)(31696002)(86362001)(66946007)(66556008)(66476007)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB7419 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT045.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 1d1afd0c-7a7b-4629-fc80-08da7169861f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JRF/tzGoUVXhw6SAXcLMdG6Svb8fggIidUUXkm8xUJDHq63obJU5PZy6f3WWNSlfSzXEEArO+TLxD2ZUqalypnYfqCSujW8rnv4Z2hiS5d079bsxmiw5/1DbQ4dkFV+xk2K3a4YXEe6M8Hnp9/6+7O/6/G6rqgI3FbZbg4AA3wAhz8/UW9vifsvuZhRaXyhSrwQIWst+dZlWu3XoV/+FaWu99ruXnfAVmGiD/w8h5pZy75IcTQtlhH8Ktw66aRLD1hAfA6oNj0OWhjwl5EYfyBNgKSf/7ywz7xJeqb4SS7Kgyhca8Fkb2cZPpQimFaFSWcZv00hGkJ5DnSUnkWWUIecvtSx7UR/rR7CkezIVEwKA5hdddKuFLEznuMrIj184j8kufxGCg7T3CLrSRJHAAcPjG7Ns9K5GrRVsSuY6dKPds+AklCtAoonDSI/JNzw9DIIgH9WbyN5Z3GkV/7f/JlG68RvQT53KZiJ8M4soL9ulXXR6E+9Vz2p0lZg3/QsJZqyieyt4XvjgYDUFlOiHTOL2k75WxPDzy8Ep8YJADHotrKbqHYDOfIWKKB5EsQZwsb7kLObDhx3t0FAV1PI4RWfXuwFfrt/aHVtSH731NwjDU3SqGRxY+9HqzfTIhkWBqUj99mT4Hl2im0OukdCvkA4Ych0KJBlEYg4onqARZBgzMTr5sE00zAtZqDdtsH/YWM+4V3SFxNTu8Qn2NzltzkRZGro90CzFrs2L35oAnTSI27wdvQOYDh3SxD/9L2q6Dr1e89mhF4v47P2Eju0vz13vLJ8ia23Yk1zEhfpgXdPgyMs553cfPv8hfU0jpwolCqn8pGBqIXv055kgSmBkHg== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230016)(4636009)(39860400002)(396003)(376002)(346002)(136003)(46966006)(40470700004)(36840700001)(6666004)(41300700001)(33964004)(478600001)(6512007)(235185007)(2906002)(8936002)(36916002)(5660300002)(40480700001)(86362001)(36756003)(82310400005)(31686004)(26005)(6506007)(6486002)(110136005)(40460700003)(31696002)(82740400003)(356005)(81166007)(47076005)(2616005)(186003)(336012)(83380400001)(8676002)(316002)(36860700001)(70206006)(70586007)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2022 13:52:21.0185 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b72a0797-882e-4a66-faf3-08da71698f01 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT045.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5640 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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 Earnshaw via Gcc-patches From: "Richard Earnshaw (lists)" Reply-To: Richard Earnshaw 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?1739615718689528586?= X-GMAIL-MSGID: =?utf-8?q?1739695368761462526?= A SET operation that writes memory may have the same value as an earlier store but if the alias sets of the new and earlier store do not conflict then the set is not truly redundant. This can happen, for example, if objects of different types share a stack slot. To fix this we define a new function in cselib that first checks for equality and if that is successful then finds the earlier store in the value history and checks the alias sets. The routine is used in two places elsewhere in the compiler. Firstly in cfgcleanup and secondly in postreload. gcc/ChangeLog: * alias.h (mems_same_for_tbaa_p): Declare. * alias.cc (mems_same_for_tbaa_p): New function. * dse.cc (record_store): Use it instead of open-coding alias check. * cselib.h (cselib_redundant_set_p): Declare. * cselib.cc: Include alias.h (cselib_redundant_set_p): New function. * cfgcleanup.cc: (mark_effect): Use cselib_redundant_set_p instead of rtx_equal_for_cselib_p. * postreload.c (reload_cse_simplify): Use cselib_redundant_set_p. (reload_cse_noop_set_p): Delete. diff --git a/gcc/alias.cc b/gcc/alias.cc index 8c08452e0ac..d54feb15268 100644 --- a/gcc/alias.cc +++ b/gcc/alias.cc @@ -389,6 +389,20 @@ refs_same_for_tbaa_p (tree earlier, tree later) || alias_set_subset_of (later_base_set, earlier_base_set)); } +/* Similar to refs_same_for_tbaa_p() but for use on MEM rtxs. */ +bool +mems_same_for_tbaa_p (rtx earlier, rtx later) +{ + gcc_assert (MEM_P (earlier)); + gcc_assert (MEM_P (later)); + + return ((MEM_ALIAS_SET (earlier) == MEM_ALIAS_SET (later) + || alias_set_subset_of (MEM_ALIAS_SET (later), + MEM_ALIAS_SET (earlier))) + && (!MEM_EXPR (earlier) + || refs_same_for_tbaa_p (MEM_EXPR (earlier), MEM_EXPR (later)))); +} + /* Returns a pointer to the alias set entry for ALIAS_SET, if there is such an entry, or NULL otherwise. */ diff --git a/gcc/alias.h b/gcc/alias.h index b2596518ac9..ee3db466763 100644 --- a/gcc/alias.h +++ b/gcc/alias.h @@ -40,6 +40,7 @@ tree reference_alias_ptr_type_1 (tree *); bool alias_ptr_types_compatible_p (tree, tree); int compare_base_decls (tree, tree); bool refs_same_for_tbaa_p (tree, tree); +bool mems_same_for_tbaa_p (rtx, rtx); /* This alias set can be used to force a memory to conflict with all other memories, creating a barrier across which no memory reference diff --git a/gcc/cfgcleanup.cc b/gcc/cfgcleanup.cc index 18047da7b24..a8b0139bb4d 100644 --- a/gcc/cfgcleanup.cc +++ b/gcc/cfgcleanup.cc @@ -208,7 +208,7 @@ mark_effect (rtx exp, regset nonequal) return false; case SET: - if (rtx_equal_for_cselib_p (SET_DEST (exp), SET_SRC (exp))) + if (cselib_redundant_set_p (exp)) return false; dest = SET_DEST (exp); if (dest == pc_rtx) diff --git a/gcc/cselib.cc b/gcc/cselib.cc index 6769beeeaf8..6a5609786fa 100644 --- a/gcc/cselib.cc +++ b/gcc/cselib.cc @@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see #include "dumpfile.h" #include "cselib.h" #include "function-abi.h" +#include "alias.h" /* A list of cselib_val structures. */ struct elt_list @@ -1157,6 +1158,75 @@ rtx_equal_for_cselib_1 (rtx x, rtx y, machine_mode memmode, int depth) return 1; } +/* Wrapper for rtx_equal_for_cselib_p to determine whether a SET is + truly redundant, taking into account aliasing information. */ +bool +cselib_redundant_set_p (rtx set) +{ + gcc_assert (GET_CODE (set) == SET); + rtx dest = SET_DEST (set); + if (cselib_reg_set_mode (dest) != GET_MODE (dest)) + return false; + + if (!rtx_equal_for_cselib_p (dest, SET_SRC (set))) + return false; + + while (GET_CODE (dest) == SUBREG + || GET_CODE (dest) == ZERO_EXTRACT + || GET_CODE (dest) == STRICT_LOW_PART) + dest = XEXP (dest, 0); + + if (!flag_strict_aliasing || !MEM_P (dest)) + return true; + + /* For a store we need to check that suppressing it will not change + the effective alias set. */ + rtx dest_addr = XEXP (dest, 0); + + /* Lookup the equivalents to the original dest (rather than just the + MEM). */ + cselib_val *src_val = cselib_lookup (SET_DEST (set), + GET_MODE (SET_DEST (set)), + 0, VOIDmode); + + if (src_val) + { + /* Walk the list of source equivalents to find the MEM accessing + the same location. */ + for (elt_loc_list *l = src_val->locs; l; l = l->next) + { + rtx src_equiv = l->loc; + while (GET_CODE (src_equiv) == SUBREG + || GET_CODE (src_equiv) == ZERO_EXTRACT + || GET_CODE (src_equiv) == STRICT_LOW_PART) + src_equiv = XEXP (src_equiv, 0); + + if (MEM_P (src_equiv)) + { + /* Match the MEMs by comparing the addresses. We can + only remove the later store if the earlier aliases at + least all the accesses of the later one. */ + if (rtx_equal_for_cselib_1 (dest_addr, XEXP (src_equiv, 0), + GET_MODE (dest), 0)) + return mems_same_for_tbaa_p (src_equiv, dest); + } + } + } + + /* We failed to find a recorded value in the cselib history, so try + the source of this set; this catches cases such as *p = *q when p + and q have the same value. */ + rtx src = SET_SRC (set); + while (GET_CODE (src) == SUBREG) + src = XEXP (src, 0); + + if (MEM_P (src) + && rtx_equal_for_cselib_1 (dest_addr, XEXP (src, 0), GET_MODE (dest), 0)) + return mems_same_for_tbaa_p (src, dest); + + return false; +} + /* Helper function for cselib_hash_rtx. Arguments like for cselib_hash_rtx, except that it hashes (plus:P x c). */ diff --git a/gcc/cselib.h b/gcc/cselib.h index 9ae65e6459e..b0905053ea5 100644 --- a/gcc/cselib.h +++ b/gcc/cselib.h @@ -83,6 +83,7 @@ extern void cselib_process_insn (rtx_insn *); extern bool fp_setter_insn (rtx_insn *); extern machine_mode cselib_reg_set_mode (const_rtx); extern int rtx_equal_for_cselib_1 (rtx, rtx, machine_mode, int); +extern bool cselib_redundant_set_p (rtx); extern int references_value_p (const_rtx, int); extern rtx cselib_expand_value_rtx (rtx, bitmap, int); typedef rtx (*cselib_expand_callback)(rtx, bitmap, int, void *); diff --git a/gcc/dse.cc b/gcc/dse.cc index 90a4c1f22db..0f7b0fb9796 100644 --- a/gcc/dse.cc +++ b/gcc/dse.cc @@ -1570,12 +1570,7 @@ record_store (rtx body, bb_info_t bb_info) width) /* We can only remove the later store if the earlier aliases at least all accesses the later one. */ - && ((MEM_ALIAS_SET (mem) == MEM_ALIAS_SET (s_info->mem) - || alias_set_subset_of (MEM_ALIAS_SET (mem), - MEM_ALIAS_SET (s_info->mem))) - && (!MEM_EXPR (s_info->mem) - || refs_same_for_tbaa_p (MEM_EXPR (s_info->mem), - MEM_EXPR (mem))))) + && mems_same_for_tbaa_p (s_info->mem, mem)) { if (GET_MODE (mem) == BLKmode) { diff --git a/gcc/postreload.cc b/gcc/postreload.cc index d1c99fe6dc9..41f61d32648 100644 --- a/gcc/postreload.cc +++ b/gcc/postreload.cc @@ -43,7 +43,6 @@ along with GCC; see the file COPYING3. If not see #include "function-abi.h" #include "rtl-iter.h" -static int reload_cse_noop_set_p (rtx); static bool reload_cse_simplify (rtx_insn *, rtx); static void reload_cse_regs_1 (void); static int reload_cse_simplify_set (rtx, rtx_insn *); @@ -74,16 +73,6 @@ reload_cse_regs (rtx_insn *first ATTRIBUTE_UNUSED) } } -/* See whether a single set SET is a noop. */ -static int -reload_cse_noop_set_p (rtx set) -{ - if (cselib_reg_set_mode (SET_DEST (set)) != GET_MODE (SET_DEST (set))) - return 0; - - return rtx_equal_for_cselib_p (SET_DEST (set), SET_SRC (set)); -} - /* Try to simplify INSN. Return true if the CFG may have changed. */ static bool reload_cse_simplify (rtx_insn *insn, rtx testreg) @@ -118,7 +107,7 @@ reload_cse_simplify (rtx_insn *insn, rtx testreg) this out, so it's safer to simplify before we delete. */ count += reload_cse_simplify_set (body, insn); - if (!count && reload_cse_noop_set_p (body)) + if (!count && cselib_redundant_set_p (body)) { if (check_for_inc_dec (insn)) delete_insn_and_edges (insn); @@ -157,7 +146,7 @@ reload_cse_simplify (rtx_insn *insn, rtx testreg) rtx part = XVECEXP (body, 0, i); if (GET_CODE (part) == SET) { - if (! reload_cse_noop_set_p (part)) + if (! cselib_redundant_set_p (part)) break; if (REG_P (SET_DEST (part)) && REG_FUNCTION_VALUE_P (SET_DEST (part)))