From patchwork Mon Oct 23 13:31:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Coplan X-Patchwork-Id: 156887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1300515vqx; Mon, 23 Oct 2023 06:32:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHx+oN3N5g/6ntOH/AMi18KZuD9RY+RrfdGesmAqjoh1abSXnfZL42351GAnHP61fE6Nt0Z X-Received: by 2002:a05:620a:2484:b0:774:32a7:fe91 with SMTP id i4-20020a05620a248400b0077432a7fe91mr11612935qkn.48.1698067978914; Mon, 23 Oct 2023 06:32:58 -0700 (PDT) Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bl33-20020a05620a1aa100b0077390297474si3470741qkb.347.2023.10.23.06.32.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 06:32:58 -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=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=zvFrjOyK; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=zvFrjOyK; arc=fail (previous hop failed); 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A76CA3858C39 for ; Mon, 23 Oct 2023 13:32:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2073.outbound.protection.outlook.com [40.107.8.73]) by sourceware.org (Postfix) with ESMTPS id 0EEE0385842E for ; Mon, 23 Oct 2023 13:32:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0EEE0385842E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0EEE0385842E Authentication-Results: server2.sourceware.org; arc=fail smtp.remote-ip=40.107.8.73 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1698067923; cv=fail; b=D2bZgCZ5xTz84PfXmhdmTsfPqDaKqXee26JAHRL9hsj2Qc9KO2SnbMNY0KKzbNFB1cFAk6peJVgq5uHLepO0fNsEuF9IiHvlqkDd9zzs1F8N1vxlFrnjcoC28fApbKy4fPU+9sZu8YSNmgprbWJZaiv/UTGcHjv5QmE3xY84GNQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1698067923; c=relaxed/simple; bh=+KvQwweBwOvQHJKyAztBupP2r2t2x6GmzjFLLB2dAS4=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=CMnmwaCqqWFhWjWMQCId41dakvjhLwX0oFKU5bo+DC3vspLMgtVuBTLxySVb4UREU5fwc6y1Jm78Hl06oxM2/4nKoOJQLDmQb3rGxWKs/d3jBTE6yahtheQsCqE/Rp91eHcOaKJqVmMzmvKyXaqgmcMFOcJIQTIiQ9NVrMz8WI4= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k0tNsrcOk6oUIVRzm390bQz7YtdckyXMtcbOiMFbiW4=; b=zvFrjOyKBCB8FKH0FJCiCpOTkPF3nnML57Aui6ByxU0m9GzvUm+O75YDrJJxU7pzu/lna0JZyUW3zQyeildT8vqeEv3RL5p2LcdY77vebPXuAdHRYrM5vyysnTSrtGQvFrjCFae3NnpZ+PTmIEMDJXrfs0j3/ar8sAt3OuMc0qw= Received: from AS9PR0301CA0007.eurprd03.prod.outlook.com (2603:10a6:20b:468::27) by AS8PR08MB7321.eurprd08.prod.outlook.com (2603:10a6:20b:440::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Mon, 23 Oct 2023 13:31:57 +0000 Received: from AM1PEPF000252DB.eurprd07.prod.outlook.com (2603:10a6:20b:468:cafe::26) by AS9PR0301CA0007.outlook.office365.com (2603:10a6:20b:468::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Mon, 23 Oct 2023 13:31:57 +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 AM1PEPF000252DB.mail.protection.outlook.com (10.167.16.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.16 via Frontend Transport; Mon, 23 Oct 2023 13:31:56 +0000 Received: ("Tessian outbound d1b3e404ba03:v215"); Mon, 23 Oct 2023 13:31:56 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: f3cc0f82c51666a9 X-CR-MTA-TID: 64aa7808 Received: from ba87f1445991.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 591F6EB3-332C-4A8D-8E22-680F8B6DFF6C.1; Mon, 23 Oct 2023 13:31:49 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ba87f1445991.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 23 Oct 2023 13:31:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YvSHDbl2nlVcOXJrZ5LZaiw0IZSH7aaRX3eu4ZjSdmtIYzX5bVrfEoZpCn2/tDuAQEr92aRyEORNjplmwy11VBAHveHoBe6Vp2g279kBjYd9SY7oMNBsy6FtjPAvBg3bwHA6HKHX6ePpX6Q5im7cE314gmbdMyh1TgWtJfQI+okEEZ1rTIxulT+nMEAc6X8Au8tTT0hj3na5d3vOJpfWDWxYfk2ET+pH5tvkRyqLKb8pcvX/rsSKqHr7WFgtivV8nPWJBtKJsWwv5DwUwYVWkPd7MAOwCs70MY3r8/nwwOQr8teApSLijaqdObl1Ir/bheaTJ3CdAegrWcPgIimAJQ== 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=k0tNsrcOk6oUIVRzm390bQz7YtdckyXMtcbOiMFbiW4=; b=kLyvaoMdeRzb0HhfZQlLodgOsafg/nvTzWphsiCX/8N3NOi2F3+a9PDCnElrXjpJQUDFiJ2o1keXUU8k4uM2uoee/oSy5xlTAjIwO1IREAfVYiF9AxwFg1bpdkK9KYX8RaexqO50HnCz8IkP5Mq1vysNDfJXp+JIO9zbnSUoD8qtk6GgtEsz2yEX5oXXSOnpvz9EpgZlsXEyj4wa2Vwz1pdNhqhQx0WH2+TH63dsFuwUI9ekSaNNtL3Q8evaE8iDNhLuoJBcJMHoVbyejKe5sOqu16zuiDS1qFGBm93m8QImp8BhbS/gKaVlAjkuM8kUCBjW8Rk13hIli1bWXBupHg== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k0tNsrcOk6oUIVRzm390bQz7YtdckyXMtcbOiMFbiW4=; b=zvFrjOyKBCB8FKH0FJCiCpOTkPF3nnML57Aui6ByxU0m9GzvUm+O75YDrJJxU7pzu/lna0JZyUW3zQyeildT8vqeEv3RL5p2LcdY77vebPXuAdHRYrM5vyysnTSrtGQvFrjCFae3NnpZ+PTmIEMDJXrfs0j3/ar8sAt3OuMc0qw= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from PAWPR08MB8958.eurprd08.prod.outlook.com (2603:10a6:102:33e::15) by AS8PR08MB9906.eurprd08.prod.outlook.com (2603:10a6:20b:564::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.29; Mon, 23 Oct 2023 13:31:46 +0000 Received: from PAWPR08MB8958.eurprd08.prod.outlook.com ([fe80::8512:cc10:24d4:1919]) by PAWPR08MB8958.eurprd08.prod.outlook.com ([fe80::8512:cc10:24d4:1919%5]) with mapi id 15.20.6907.032; Mon, 23 Oct 2023 13:31:46 +0000 Date: Mon, 23 Oct 2023 14:31:44 +0100 From: Alex Coplan To: gcc-patches@gcc.gnu.org Cc: Richard Biener , Jakub Jelinek Subject: Backport PR106878 fixes to GCC 12 Message-ID: Content-Disposition: inline X-ClientProxiedBy: LNXP265CA0024.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5e::36) To PAWPR08MB8958.eurprd08.prod.outlook.com (2603:10a6:102:33e::15) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: PAWPR08MB8958:EE_|AS8PR08MB9906:EE_|AM1PEPF000252DB:EE_|AS8PR08MB7321:EE_ X-MS-Office365-Filtering-Correlation-Id: be764e44-3248-469e-5049-08dbd3cc6d45 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: fWudNtv+VZT5fuedln7ox9V3c+Oceu3/CO3nigiAraLAFX27Y8zeo8gBmL4SPLU24d6HiihfqUZGEWEMO2EuYk1YrVauFEKXweKJ5A5jUx4Lw6dULutDdUByeJ09co1pb/+HKPp9eiWfbbfxCQRVAZbg/9sJL5s2PXsqo9vsgm1qAwjwEpHqmaHsMdyu5tyux20peszdm0eeVcx/iCdacvEgQQiDPBv27XbjdZQulwa7E3CeMCXWzlq4+bspYLCawkSSw/CmoLY8zi1nUwC/f70Vrx7wNYM6otu1zmdHoYUmZ0azXUwyvccYEsldOy4i5kZ0scAMKeE4XZTIlBTjpOqu67rSViBGQlrwqhKGzp+krQxl/UkdfJ/UgvX24Lkay3Iq2KW9yF9jfTrFizADoGwA8IJ83YlBSbFPCxXGxxg7DgXWeUNivhVVRhzIK+W3ytJYlD/4LRMNk7xLTzvSC6zieilzyC8jEsunJxwxFJjDf5ffp+OaZpPAhxmoIMm4xT41yAOd0VvV9gcAedF4tIxhZqraRojUz+8V7leDwUFuWBPtcO8WKqmgp3fFlAh3PSenCkptzkSeTrhCAaBduGMahyA1xyvI3UKEm4yUMRk= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAWPR08MB8958.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(39860400002)(396003)(366004)(376002)(136003)(346002)(230922051799003)(64100799003)(186009)(451199024)(1800799009)(2906002)(38100700002)(41300700001)(66476007)(316002)(66556008)(66946007)(54906003)(6916009)(235185007)(6506007)(33964004)(478600001)(44144004)(966005)(6486002)(6512007)(21490400003)(83380400001)(44832011)(36756003)(5660300002)(86362001)(8936002)(8676002)(4326008)(2616005)(26005)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9906 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: AM1PEPF000252DB.eurprd07.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: e88c0905-c9b7-403f-8bf3-08dbd3cc6763 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: abOoA2e0NvvKBJ6/cXyJnT6zaKMMSAjp0A5/PZsTgWUED/j4edc1I353rgcgfKJz//dvM3ja/4BESQoFLOdLfuybycXa0x07XIhcW1APO1hWiT6kXE4+Js5L3mMJXsHR2eI+rf9JzNWjJDn2w37gb2OVDiTbUtUHT27ffgy1kv8oSidA9B/0EtveSEZSHP6efb7AGCc08X9yppXU758jY+ASVNLWLlJhcnyxCkwHgYGsovZ1psOEvG5g7WoI5FWeUPqGJn1oAGZv00nMYAemAwMcsN71US4NAxTxgrpu4KDeTdB/wjbuiSXqyNhUhx2fRKZGnPj+u3ybsB6qru0fWScBjHAIHOiyA/iWMga3YfzFX89oVFC0ph8FDAOVGNkKipC4XchnMbXvi1CLHR6YLbJ/xS+KjAxLNtilF24DmCjIEDh9PhghN+84DtB5hsj/kSaOcXeHK3RAS56FDis1dlu51lYfkVDs7qEi/aGUpk4Zg+DM2xryGchK+6BseNcT8yuw2XWWdfJz9110RtA0fGcVMvMZsYYkWkLq2W7igoIxYr2XZlYsEcDM85xu0ozQB+ZiYQAM+dOerruj3iwYvPIAX95e3/ebTjX4XsYmM+UwKaaCLAHOC8eKQjQSh8K0WSPDTgIC8ylefLOU4QnRQVoKMC3JbJkZl02NEjPpA37aafkKaOiHPZpSX0bJi8IQFq31TIYeYgF+EYdNr5jDGAepVZJq33oSQoS7ODyKBsAuHc643Bwzk45kh9Up3aumYJVxw7KegY+ygh2cpU4vng== 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:(13230031)(4636009)(136003)(346002)(396003)(376002)(39860400002)(230922051799003)(64100799003)(1800799009)(186009)(82310400011)(451199024)(46966006)(40470700004)(36840700001)(41300700001)(2906002)(36860700001)(356005)(70206006)(54906003)(70586007)(82740400003)(316002)(6916009)(107886003)(33964004)(2616005)(6506007)(44144004)(478600001)(81166007)(40480700001)(6512007)(966005)(47076005)(21490400003)(336012)(83380400001)(6486002)(5660300002)(44832011)(40460700003)(235185007)(36756003)(86362001)(4326008)(8676002)(8936002)(26005)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2023 13:31:56.2480 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: be764e44-3248-469e-5049-08dbd3cc6d45 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: AM1PEPF000252DB.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB7321 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, KAM_NUMSUBJECT, KAM_SHORT, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780553328972013382 X-GMAIL-MSGID: 1780553328972013382 Hi, I'd like to submit the attached three patches from Jakub for backporting to GCC 12. These are the backports proposed at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106878#c18 i.e.: r13-2658-g645ef01a463f15fc230e2155719c7a12cec89acf without the gimple verifier changes. r13-2709-g9ac9fde961f76879f0379ff3b2494a2f9ac915f7 r13-2891-gcb8f25c5dc9f6d5207c826c2dafe25f68458ceaf For the first patch, I was thinking of backporting it with the cover letter as follows: Disallow pointer operands for |, ^ and partly & [PR106878] This is a backport of 645ef01a463f15fc230e2155719c7a12cec89acf without the changes to verify_gimple_assign_binary from the original patch. The original cover letter for the patch is as follows: My change to match.pd (that added the two simplifications this patch touches) results in more |/^/& assignments with pointer arguments, but since r12-1608 we reject pointer operands for BIT_NOT_EXPR. Disallowing them for BIT_NOT_EXPR and allowing for BIT_{IOR,XOR,AND}_EXPR leads to a match.pd maintainance nightmare (see one of the patches in the PR), so either we want to allow pointer operand on BIT_NOT_EXPR (but then we run into issues e.g. with the ranger which expects it can emulate BIT_NOT_EXPR ~X as - 1 - X which doesn't work for pointers which don't support MINUS_EXPR), or the following patch disallows pointer arguments for all of BIT_{IOR,XOR,AND}_EXPR with the exception of BIT_AND_EXPR with INTEGER_CST last operand (for simpler pointer realignment). I had to tweak one reassoc optimization and the two match.pd simplifications. 2022-09-14 Jakub Jelinek PR tree-optimization/106878 * match.pd ((type) X op CST -> (type) (X op ((type-x) CST)), (type) (((type2) X) op Y) -> (X op (type) Y)): Punt for POINTER_TYPE_P or OFFSET_TYPE. * tree-ssa-reassoc.cc (optimize_range_tests_cmp_bitwise): For pointers cast them to pointer sized integers first. * gcc.c-torture/compile/pr106878.c: New test. ------ The other two patches can then be simple cherry picks. (Or we could squash them into a single patch, if that's deemed preferable). I've bootstrapped and tested these on top of the GCC 12 branch on both x86_64-linux-gnu and aarch64-linux-gnu, and there were no regressions. OK for the GCC 12 branch? Thanks, Alex commit 557c126f9fbdcde256f134d4ed34ff305387fd41 Author: Jakub Jelinek Date: Wed Sep 14 11:36:36 2022 Disallow pointer operands for |, ^ and partly & [PR106878] This is a backport of 645ef01a463f15fc230e2155719c7a12cec89acf without the changes to verify_gimple_assign_binary from the original patch. The original cover letter for the patch is as follows: My change to match.pd (that added the two simplifications this patch touches) results in more |/^/& assignments with pointer arguments, but since r12-1608 we reject pointer operands for BIT_NOT_EXPR. Disallowing them for BIT_NOT_EXPR and allowing for BIT_{IOR,XOR,AND}_EXPR leads to a match.pd maintainance nightmare (see one of the patches in the PR), so either we want to allow pointer operand on BIT_NOT_EXPR (but then we run into issues e.g. with the ranger which expects it can emulate BIT_NOT_EXPR ~X as - 1 - X which doesn't work for pointers which don't support MINUS_EXPR), or the following patch disallows pointer arguments for all of BIT_{IOR,XOR,AND}_EXPR with the exception of BIT_AND_EXPR with INTEGER_CST last operand (for simpler pointer realignment). I had to tweak one reassoc optimization and the two match.pd simplifications. 2022-09-14 Jakub Jelinek PR tree-optimization/106878 * match.pd ((type) X op CST -> (type) (X op ((type-x) CST)), (type) (((type2) X) op Y) -> (X op (type) Y)): Punt for POINTER_TYPE_P or OFFSET_TYPE. * tree-ssa-reassoc.cc (optimize_range_tests_cmp_bitwise): For pointers cast them to pointer sized integers first. * gcc.c-torture/compile/pr106878.c: New test. commit 7f7f6f483863ad9e38cd08e26576b6b9281157d1 Author: Jakub Jelinek Date: Sat Sep 17 07:18:24 2022 reassoc: Fix up recent regression in optimize_range_tests_cmp_bitwise [PR106958] As the following testcase reduced from glibc fmtmsg.c shows (it doesn't ICE on x86_64/i686 unfortunately, but does on various other arches), my last optimize_range_tests_cmp_bitwise change wasn't fully correct. The intent was to let all pointer operands be cast to pointer_sized_int_node first in addition to the other casts (to type1) which are done for id >= l cases. But one spot I've touched used always cast to type1 (note, the (b % 4) == 3 case is impossible for pointer operands because that is for !TYPE_UNSIGNED operands and pointers are TYPE_UNSIGNED) and in the other spot the cast would be done only for id >= l if not useless, but for pointers we need to cast it always. 2022-09-17 Jakub Jelinek PR tree-optimization/106958 * tree-ssa-reassoc.cc (optimize_range_tests_cmp_bitwise): If id >= l, cast op to type1, otherwise to pointer_sized_int_node. If type has pointer type, cast exp to pointer_sized_int_node even when id < l. * gcc.c-torture/compile/pr106958.c: New test. (cherry picked from commit 9ac9fde961f76879f0379ff3b2494a2f9ac915f7) diff --git a/gcc/testsuite/gcc.c-torture/compile/pr106958.c b/gcc/testsuite/gcc.c-torture/compile/pr106958.c new file mode 100644 index 00000000000..98e6554c736 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr106958.c @@ -0,0 +1,13 @@ +/* PR tree-optimization/106958 */ + +int a; +void bar (int); + +void +foo (char *x, char *y) +{ + int b = a != 0; + int c = x != 0; + int d = y != 0; + bar (b | c | d); +} diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc index 6baef476471..a4fcd0f35d9 100644 --- a/gcc/tree-ssa-reassoc.cc +++ b/gcc/tree-ssa-reassoc.cc @@ -3689,15 +3689,18 @@ optimize_range_tests_cmp_bitwise (enum tree_code opcode, int first, int length, if (id == l || POINTER_TYPE_P (TREE_TYPE (op))) { code = (b % 4) == 3 ? BIT_NOT_EXPR : NOP_EXPR; - g = gimple_build_assign (make_ssa_name (type1), code, op); + tree type3 = id >= l ? type1 : pointer_sized_int_node; + g = gimple_build_assign (make_ssa_name (type3), code, op); gimple_seq_add_stmt_without_update (&seq, g); op = gimple_assign_lhs (g); } tree type = TREE_TYPE (r->exp); tree exp = r->exp; - if (id >= l && !useless_type_conversion_p (type1, type)) + if (POINTER_TYPE_P (type) + || (id >= l && !useless_type_conversion_p (type1, type))) { - g = gimple_build_assign (make_ssa_name (type1), NOP_EXPR, exp); + tree type3 = id >= l ? type1 : pointer_sized_int_node; + g = gimple_build_assign (make_ssa_name (type3), NOP_EXPR, exp); gimple_seq_add_stmt_without_update (&seq, g); exp = gimple_assign_lhs (g); } commit 3d6914b0dfd595a091723d95aba1641b0bdbe4fb Author: Jakub Jelinek Date: Tue Sep 27 07:26:18 2022 reassoc: Handle OFFSET_TYPE like POINTER_TYPE in optimize_range_tests_cmp_bitwise [PR107029[ As the testcase shows, OFFSET_TYPE needs the same treatment as POINTER_TYPE/REFERENCE_TYPE, otherwise we fail the same during the newly added verification. OFFSET_TYPE is signed though, so unlike POINTER_TYPE/REFERENCE_TYPE it can also trigger with the x < 0 && y < 0 && z < 0 to (x | y | z) < 0 optimization. 2022-09-27 Jakub Jelinek PR tree-optimization/107029 * tree-ssa-reassoc.cc (optimize_range_tests_cmp_bitwise): Treat OFFSET_TYPE like POINTER_TYPE, except that OFFSET_TYPE may be signed and so can trigger even the (b % 4) == 3 case. * g++.dg/torture/pr107029.C: New test. (cherry picked from commit cb8f25c5dc9f6d5207c826c2dafe25f68458ceaf) diff --git a/gcc/testsuite/g++.dg/torture/pr107029.C b/gcc/testsuite/g++.dg/torture/pr107029.C new file mode 100644 index 00000000000..93c7f28fb4c --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr107029.C @@ -0,0 +1,19 @@ +// PR tree-optimization/107029 +// { dg-do compile } + +struct S { long long a; int b; }; +long long S::*a; +int S::*b; +struct A { void foo (bool, bool); void bar (); int c; }; + +void +A::foo (bool a, bool b) +{ + c = a || b; +} + +void +A::bar() +{ + foo (a, b); +} diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc index a4fcd0f35d9..61d718aa46a 100644 --- a/gcc/tree-ssa-reassoc.cc +++ b/gcc/tree-ssa-reassoc.cc @@ -3617,13 +3617,13 @@ optimize_range_tests_cmp_bitwise (enum tree_code opcode, int first, int length, tree type2 = NULL_TREE; bool strict_overflow_p = false; candidates.truncate (0); - if (POINTER_TYPE_P (type1)) + if (POINTER_TYPE_P (type1) || TREE_CODE (type1) == OFFSET_TYPE) type1 = pointer_sized_int_node; for (j = i; j; j = chains[j - 1]) { tree type = TREE_TYPE (ranges[j - 1].exp); strict_overflow_p |= ranges[j - 1].strict_overflow_p; - if (POINTER_TYPE_P (type)) + if (POINTER_TYPE_P (type) || TREE_CODE (type) == OFFSET_TYPE) type = pointer_sized_int_node; if ((b % 4) == 3) { @@ -3655,7 +3655,7 @@ optimize_range_tests_cmp_bitwise (enum tree_code opcode, int first, int length, tree type = TREE_TYPE (ranges[j - 1].exp); if (j == k) continue; - if (POINTER_TYPE_P (type)) + if (POINTER_TYPE_P (type) || TREE_CODE (type) == OFFSET_TYPE) type = pointer_sized_int_node; if ((b % 4) == 3) { @@ -3686,10 +3686,20 @@ optimize_range_tests_cmp_bitwise (enum tree_code opcode, int first, int length, op = r->exp; continue; } - if (id == l || POINTER_TYPE_P (TREE_TYPE (op))) + if (id == l + || POINTER_TYPE_P (TREE_TYPE (op)) + || TREE_CODE (TREE_TYPE (op)) == OFFSET_TYPE) { code = (b % 4) == 3 ? BIT_NOT_EXPR : NOP_EXPR; tree type3 = id >= l ? type1 : pointer_sized_int_node; + if (code == BIT_NOT_EXPR + && TREE_CODE (TREE_TYPE (op)) == OFFSET_TYPE) + { + g = gimple_build_assign (make_ssa_name (type3), + NOP_EXPR, op); + gimple_seq_add_stmt_without_update (&seq, g); + op = gimple_assign_lhs (g); + } g = gimple_build_assign (make_ssa_name (type3), code, op); gimple_seq_add_stmt_without_update (&seq, g); op = gimple_assign_lhs (g); @@ -3697,6 +3707,7 @@ optimize_range_tests_cmp_bitwise (enum tree_code opcode, int first, int length, tree type = TREE_TYPE (r->exp); tree exp = r->exp; if (POINTER_TYPE_P (type) + || TREE_CODE (type) == OFFSET_TYPE || (id >= l && !useless_type_conversion_p (type1, type))) { tree type3 = id >= l ? type1 : pointer_sized_int_node; @@ -3714,7 +3725,7 @@ optimize_range_tests_cmp_bitwise (enum tree_code opcode, int first, int length, op = gimple_assign_lhs (g); } type1 = TREE_TYPE (ranges[k - 1].exp); - if (POINTER_TYPE_P (type1)) + if (POINTER_TYPE_P (type1) || TREE_CODE (type1) == OFFSET_TYPE) { gimple *g = gimple_build_assign (make_ssa_name (type1), NOP_EXPR, op); diff --git a/gcc/match.pd b/gcc/match.pd index a9aae484b2b..cbae09dfb28 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1663,6 +1663,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && (int_fits_type_p (@1, TREE_TYPE (@0)) || tree_nop_conversion_p (TREE_TYPE (@0), type))) || types_match (@0, @1)) + && !POINTER_TYPE_P (TREE_TYPE (@0)) + && TREE_CODE (TREE_TYPE (@0)) != OFFSET_TYPE /* ??? This transform conflicts with fold-const.cc doing Convert (T)(x & c) into (T)x & (T)c, if c is an integer constants (if x has signed type, the sign bit cannot be set @@ -1699,7 +1701,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (GIMPLE && TREE_CODE (@1) != INTEGER_CST && tree_nop_conversion_p (type, TREE_TYPE (@2)) - && types_match (type, @0)) + && types_match (type, @0) + && !POINTER_TYPE_P (TREE_TYPE (@0)) + && TREE_CODE (TREE_TYPE (@0)) != OFFSET_TYPE) (bitop @0 (convert @1))))) (for bitop (bit_and bit_ior) diff --git a/gcc/testsuite/gcc.c-torture/compile/pr106878.c b/gcc/testsuite/gcc.c-torture/compile/pr106878.c new file mode 100644 index 00000000000..c8457189437 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr106878.c @@ -0,0 +1,15 @@ +/* PR tree-optimization/106878 */ + +typedef __INTPTR_TYPE__ intptr_t; +typedef __UINTPTR_TYPE__ uintptr_t; +int a; + +int +foo (const int *c) +{ + uintptr_t d = ((intptr_t) c | (intptr_t) &a) & 65535 << 16; + intptr_t e = (intptr_t) c; + if (d != (e & 65535 << 16)) + return 1; + return 0; +} diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc index e3d521e3267..6baef476471 100644 --- a/gcc/tree-ssa-reassoc.cc +++ b/gcc/tree-ssa-reassoc.cc @@ -3617,10 +3617,14 @@ optimize_range_tests_cmp_bitwise (enum tree_code opcode, int first, int length, tree type2 = NULL_TREE; bool strict_overflow_p = false; candidates.truncate (0); + if (POINTER_TYPE_P (type1)) + type1 = pointer_sized_int_node; for (j = i; j; j = chains[j - 1]) { tree type = TREE_TYPE (ranges[j - 1].exp); strict_overflow_p |= ranges[j - 1].strict_overflow_p; + if (POINTER_TYPE_P (type)) + type = pointer_sized_int_node; if ((b % 4) == 3) { /* For the signed < 0 cases, the types should be @@ -3651,6 +3655,8 @@ optimize_range_tests_cmp_bitwise (enum tree_code opcode, int first, int length, tree type = TREE_TYPE (ranges[j - 1].exp); if (j == k) continue; + if (POINTER_TYPE_P (type)) + type = pointer_sized_int_node; if ((b % 4) == 3) { if (!useless_type_conversion_p (type1, type)) @@ -3680,7 +3686,7 @@ optimize_range_tests_cmp_bitwise (enum tree_code opcode, int first, int length, op = r->exp; continue; } - if (id == l) + if (id == l || POINTER_TYPE_P (TREE_TYPE (op))) { code = (b % 4) == 3 ? BIT_NOT_EXPR : NOP_EXPR; g = gimple_build_assign (make_ssa_name (type1), code, op); @@ -3704,6 +3710,14 @@ optimize_range_tests_cmp_bitwise (enum tree_code opcode, int first, int length, gimple_seq_add_stmt_without_update (&seq, g); op = gimple_assign_lhs (g); } + type1 = TREE_TYPE (ranges[k - 1].exp); + if (POINTER_TYPE_P (type1)) + { + gimple *g + = gimple_build_assign (make_ssa_name (type1), NOP_EXPR, op); + gimple_seq_add_stmt_without_update (&seq, g); + op = gimple_assign_lhs (g); + } candidates.pop (); if (update_range_test (&ranges[k - 1], NULL, candidates.address (), candidates.length (), opcode, ops, op,