From patchwork Thu Apr 15 14:39:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Coplan X-Patchwork-Id: 1466672 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=sl5TbhH1; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4FLhp45xd4z9sVw for ; Fri, 16 Apr 2021 00:40:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EA00E386185A; Thu, 15 Apr 2021 14:40:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA00E386185A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1618497607; bh=RA++xzG01+WdBl0RRaTyY9p1OfZPtZm6yTM//VI6waM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=sl5TbhH1l5iCOXJmUVG9Sernpxbro6CPS9bxRXUfg7GAsC0v9fhVyyhk7Nm9WViF7 hW4iEK+zhqgQwbfDpz4iRFhLbF4vLHlGhE5BxQE35fhK5gqfjqJ1Z4Pbq0i1WW2AeT E0ogJ9Bh/gN8JQG4EiBOHwh5s3dx/Ys/zTUgD6A8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2048.outbound.protection.outlook.com [40.107.21.48]) by sourceware.org (Postfix) with ESMTPS id 5BA13383B426 for ; Thu, 15 Apr 2021 14:40:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5BA13383B426 Received: from AM6PR01CA0038.eurprd01.prod.exchangelabs.com (2603:10a6:20b:e0::15) by DB6PR08MB2934.eurprd08.prod.outlook.com (2603:10a6:6:19::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.32; Thu, 15 Apr 2021 14:39:59 +0000 Received: from VE1EUR03FT011.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:e0:cafe::af) by AM6PR01CA0038.outlook.office365.com (2603:10a6:20b:e0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 15 Apr 2021 14:39:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;gcc.gnu.org; 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT011.mail.protection.outlook.com (10.152.18.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 15 Apr 2021 14:39:58 +0000 Received: ("Tessian outbound 34291f7cb530:v90"); Thu, 15 Apr 2021 14:39:58 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: bcbd2b6eac5c8b66 X-CR-MTA-TID: 64aa7808 Received: from 5be8f213be53.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3EC864C8-B279-48F4-8E7B-6DF2171429B1.1; Thu, 15 Apr 2021 14:39:51 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 5be8f213be53.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 15 Apr 2021 14:39:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SLgzJS6ifF6Sygz5om37Naqtk3tEUeqFMHFlKAzUSlp4NeUo1YBPUiKxP6GkfTJedpnm1OAQtqiqYQgXQUGyHAv15e/YeO7o6uXe2biynDsGPU/1G6yJHr1doYb2ZP/+PJf/7ldU2MQr9/1qlrQVWkogol3ZL1LNWEdLygIZeV9qqH6oDlhsrLG0/ZeaHu3z9EbCU6rwuh8BRhQw6pQphU+H8wvmhO6Lp94F96BCrrbtBCf0XkBu0I4KEo+L2iZ21b1gWm25ZZrEiZtBtqozAkJ/1j+LSrB8aZLpynBHtAegcRya6V5tU5u9YYNyJiHCZdddtptmjGD2QHsfS9bMYw== 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-SenderADCheck; bh=RA++xzG01+WdBl0RRaTyY9p1OfZPtZm6yTM//VI6waM=; b=B1AqzTT4exFov3t9eGS2PhVwYsXrWJl4Lo9BgjHm0Zy5CC5uaNGYR20Ch65r/KlNZSTJQ/0MweLtSKfafaFM88Ltr38ZV9oLlATPjBeRaXqK+5ZW+17pCaNhUnzh3vVGFArPv8cxTQxSVf7bFCi7gptDSkP/Uwkx+O2ILBl4djxLwdscY5GJuGmARyyRe1LFukib96UAi408oD+YPa5s3WMY7HVXBZYJjtqrqXBWfY6qhfx/8JJNxvRloOjsaI6vyFybBrg+rWaGPEl52BDsIjjbcasD14OSmxFsrQiYOrxiMgdhYQZ8TBPP/bHMQIdv9+9rwMVlqg2ihnMqE/xMYQ== 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: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB4029.eurprd08.prod.outlook.com (2603:10a6:803:ec::14) by VI1PR0801MB1823.eurprd08.prod.outlook.com (2603:10a6:800:5a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Thu, 15 Apr 2021 14:39:49 +0000 Received: from VI1PR08MB4029.eurprd08.prod.outlook.com ([fe80::91e5:a54c:eda6:49b2]) by VI1PR08MB4029.eurprd08.prod.outlook.com ([fe80::91e5:a54c:eda6:49b2%4]) with mapi id 15.20.4042.016; Thu, 15 Apr 2021 14:39:49 +0000 Date: Thu, 15 Apr 2021 15:39:40 +0100 To: gcc-patches@gcc.gnu.org Subject: [PATCH] arm: Fix ICEs with compare-and-swap and -march=armv8-m.base [PR99977] Message-ID: <20210415143939.4ss6j36lyk6j6f7n@arm.com> Content-Disposition: inline User-Agent: NeoMutt/20171215 X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: SN4PR0201CA0002.namprd02.prod.outlook.com (2603:10b6:803:2b::12) To VI1PR08MB4029.eurprd08.prod.outlook.com (2603:10a6:803:ec::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from arm.com (217.140.106.54) by SN4PR0201CA0002.namprd02.prod.outlook.com (2603:10b6:803:2b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18 via Frontend Transport; Thu, 15 Apr 2021 14:39:46 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 475ebcec-0af4-4c53-0943-08d9001c5826 X-MS-TrafficTypeDiagnostic: VI1PR0801MB1823:|DB6PR08MB2934: X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:7691;OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: HGHBrO4jrwQ8hQe0O3dk4rWFuAjgyV0jAjZcbFfufggIya3cnX98g3DiRXyNRxogMePThjSNYG6fMGw04MvagJ9MAfAjztoiy1FG2bXnJJZjqggdorM3rWK1nm0eYn4XH/1BjZAwuYUZx4AVdNMd2L8RI9CVJ37anv+Wpk/iI4uOMXLNTvN3QYPKrXXb0tWPHfGn5LVnSKORE2gFhO7PP7V+U6uirV8EqvOx8khlbvre1dFzLoRx9vI6CD9nTapevNhHN0qT/in+2/qFUBAqXm9duFCYZ7SRXKp2M/yUQbmCQAyJ7VxCjDpB2RU66cKotm0fjkduo+zhKPf9Xx2224Etn4KcSrKXXAUwt1Y96hXJXYEjKefwqg/hIoHVXu+8I/Y+UF5YAVqMz2HYZ3FSYxkCuUPr3wteVUIjti+UvwEOEDl3B+2v8UI+swNAZkIZrC5pNj5oYlogKS4dEwTVB1K/5Dmh0pV2IqsyFSPm2ndbygc9sbq0QUwOKNGNUhSsEfIxqIOAK/l+YEp1tRLqotedXxsEWcu5jkayqbriz9CKbN6doygYEgj321D2AiUq1IwmIskkigQ6bS0Yifqy3t65ZhBYm2SyEJ1Jc98+Q96YFsoBYJA0y7xeB7Gxft0ZqtiPrpmd4ZjnJlaVQEgCVaGDKRXg61W23rUKM7ES48YcOI5IYONKkOy+ULrk3Kif X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB4029.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(39860400002)(376002)(396003)(366004)(136003)(8936002)(6666004)(2616005)(2906002)(66476007)(26005)(4326008)(8886007)(33964004)(38350700002)(478600001)(186003)(21480400003)(55016002)(54906003)(8676002)(86362001)(44832011)(1076003)(66556008)(52116002)(7696005)(5660300002)(316002)(36756003)(44144004)(235185007)(38100700002)(16526019)(956004)(66616009)(66946007)(6916009)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?bRUcrtijIJvhrhfSU9cBqyIKlbmA8S?= =?utf-8?q?pyMKvgnYPTQ6wWieF7O8qI2b4qW9z2f3OGKUM3V0O8AJwOeB9HdbUEt3Ww0onjGWL?= =?utf-8?q?CeAsKAHo7yeLUyiXfETLCsiIJotgHcMEy54aT/dg60g+LbvjzRLBYwLRYsqlhEF0N?= =?utf-8?q?3hyB8A68dW6ZT0mgfYsjNYQl4PkYDY8Ab4yQ7XzkrNl0ceNBqmHD6/gRTpsSfhX83?= =?utf-8?q?da/28JVaQEfVVugvuRdJqhYuawQJeKPk3eG3UuR2PB7jnhGu3KvuOtWK06JFXGpTD?= =?utf-8?q?1/S3qlqO9mEUjiUFpB4RKZ7T/IyMX6r4FkgAArC7sCllNSaR5vJZbvM7j5lmS+ilk?= =?utf-8?q?WCqTnKHa7kuRDDZUvXcJj5LuWoa4+7WsN70IPmbql0JiUyUX5YcQaN7BG7j+p9f6M?= =?utf-8?q?xWrF9/a3sv7a38MJ5kwkDN9Oqhah5nw/A5a3a1hcfbbjlIVm37AJz4QMqhF7VvgqG?= =?utf-8?q?R+Mjm/fWdw3HJPuplVVvlJqNOWhoGXEM6oDhFo1w2V3qawLwhNCGlmIYIuKa3yrCm?= =?utf-8?q?m+fsmIn898CuzNThJO/Xr91HRb+cuM3ivrmvt0ZeyMsTt7tSmKi5j1ZUQ7YtCF4y8?= =?utf-8?q?DDZfWzCzT3eieRu+FqKBZiv0gkznyOQBd2oU7zW+ViLcsHk7H1GW9YAtFMKEn8rJy?= =?utf-8?q?v4xz6NlqHfPfzrIxRBfzLzHxfHdJ1eGVpeG1VJIkzpQn/6JwDEwRpFpESrMi24+up?= =?utf-8?q?q0ei9xLR1n+3zLuFuR9NpsMPSA7S07J8TIf4/ZFq9n+wgMQ+WAakEy2C8qZ+xLM2B?= =?utf-8?q?OXz+jnJ+pfc9GbWm4Sl0B5zUoI3C9JIKPHYZI3phYA/11hSPm69aH0dTfklizeBkV?= =?utf-8?q?fu91Mx4pndZiraD0QTxJoLuipUTQdkNi9WH1ZM0NBdub93dK3AEWycKafx8UBEGJE?= =?utf-8?q?Z/EjE4U0Uy0n5gkzw10AhLNZTK3TGOKy9l1hp3GfjVyG4m6uzS13nVVxPM52qsvDK?= =?utf-8?q?nt6VZpmiZzJeMwki74sscAK9M1Bjae2/8Lxjm3bVK5pqFvM+BzObPxXlQ5i+sZhru?= =?utf-8?q?UrUJ0XMaVqw+stovS0SR410gECZ57p4Oi0zd+2j2Z0F6vvm8Gc7VKS9x6DKFcAjvi?= =?utf-8?q?+98JSJJ15TgCnGVUZaPQJiWU69VF/ps+srfwfZHvKd22wR0cohp5GV5r5QVK1/3WI?= =?utf-8?q?liDgmChAJo5ud9H50hlfdYeXfHiK2dtORJvVMEkKdhvzmz4+h2sPn/FD41g+uM5Ii?= =?utf-8?q?v4TZrHfqwI2GYaCG00CHCTUIReviTUICulX2oX3RKGE1TlXFW/EmUlgTRS42E54jL?= =?utf-8?q?v0v5IunAzc//go?= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1823 Original-Authentication-Results: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT011.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 41fac48c-8763-4bbb-6f11-08d9001c5229 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rfZIjBli+1SmPxwmUYoDh083IwHIm0tvwr4fMBSnj9Ihqv1VW7ACkMnWtwimTLIG3qCg9Z7jIPChrPkV+3UuAXSIPfs9FyyGCNp1yfo5KQKL0uidsERoIu4/+E87RiZd//WvqDCeBSdPi9X4maKwIw6h7vGoKQKOOYlx+bxmfWl/lH9/6fF1RbrDoGH7dVHG33aXg9cks1dMX9CQ9PRTsyxl6pvRRwwYQSUXW9+Vuy+WPuFUvVamvVnxlgLW8oq+s7XxTrd+pI7GV5EmUwREygPz5Xtl1hEzMAXcxkLsNJXGn36kjEHe2/ex3CnqSGjHEccm+V1/v/PloSEjfpwa/quXOXzlJDaWad50pkGoxw5BCTi7m23+BtK4MJkrbNZS3LE1lGvp170MM2tzV3WJE7etsLMvrqWKZmvB6VKhVhnyP8niI8obv+aS3AVH51rwXQqTOTM60Fg7mvEyJb5PN1OdjGUcxp+bJ0kSJuSZBk9EiuC4CRenwOiIlMM2zK+DdWh9sFcLNjDO8VL8gxd1jtqUwAT5mJa2cQBhezGHO+cXGYi/apLxxdeg7cTvP3v9rpNm3EA297XmZL5WUBFMV+k+cV5fLjGvOJ2ZUED/gpLnd0uZ0ZfYy/P/xYuQ/TKeqTb4cI3gwemktTezaUbfrkdFDe7kKO/TQx5BNsUqOqUsGOsMlZc1egLd4uB5/XXS 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:(4636009)(376002)(346002)(396003)(39860400002)(136003)(46966006)(36840700001)(82310400003)(8886007)(44832011)(70206006)(4326008)(8936002)(7696005)(44144004)(2906002)(5660300002)(1076003)(47076005)(235185007)(21480400003)(478600001)(33964004)(356005)(55016002)(66616009)(70586007)(36860700001)(6916009)(186003)(54906003)(86362001)(2616005)(16526019)(8676002)(36756003)(26005)(6666004)(316002)(956004)(336012)(82740400003)(81166007)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 14:39:58.5828 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 475ebcec-0af4-4c53-0943-08d9001c5826 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: VE1EUR03FT011.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR08MB2934 X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY 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: , X-Patchwork-Original-From: Alex Coplan via Gcc-patches From: Alex Coplan Reply-To: Alex Coplan Cc: Richard Earnshaw , Ramana Radhakrishnan Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi all, The PR shows two ICEs with __sync_bool_compare_and_swap and -mcpu=cortex-m23 (equivalently, -march=armv8-m.base): one in LRA and one later on, after the CAS insn is split. The LRA ICE occurs because the @atomic_compare_and_swap_1 pattern attempts to tie two output operands together (operands 0 and 1 in the third alternative). LRA can't handle this, since it doesn't make sense for an insn to assign to the same operand twice. The later (post-splitting) ICE occurs because the expansion of the cbranchsi4_scratch insn doesn't quite go according to plan. As it stands, arm_split_compare_and_swap calls gen_cbranchsi4_scratch, attempting to pass a register (neg_bval) to use as a scratch register. However, since the RTL template has a match_scratch here, gen_cbranchsi4_scratch ignores this argument and produces a scratch rtx. Since this is all happening after RA, this is doomed to fail (and we get an ICE about the insn not matching its constraints). It seems that the motivation for the choice of constraints in the atomic_compare_and_swap pattern comes from an attempt to satisfy the constraints of the cbranchsi4_scratch insn. This insn requires the scratch register to be the same as the input register in the case that we use a larger negative immediate (one that satisfies J, but not L). Of course, as noted above, LRA refuses to assign two output operands to the same register, so this was never going to work. The solution I'm proposing here is to collapse the alternatives to the CAS insn (allowing the two output register operands to be matched to different registers) and to ensure that the constraints for cbranchsi4_scratch are met in arm_split_compare_and_swap. We do this by inserting a move to ensure the source and destination registers match if necessary (i.e. in the case of large negative immediates). Another notable change here is that we only do: emit_move_insn (neg_bval, const1_rtx); for non-negative immediates. This is because the ADDS instruction used in the negative case suffices to leave a suitable value in neg_bval: if the operands compare equal, we don't take the branch (so neg_bval will be set by the load exclusive). Otherwise, the ADDS will leave a nonzero value in neg_bval, which will correctly signal that the CAS has failed when it is later negated. Testing: * Bootstrapped and regtested on arm-linux-gnueabihf, no regressions. * Regtested an arm-eabi cross configured with --with-arch=armv8-m.base, no regressions. The patch fixes the gcc.dg/ia64-sync-3.c test in this config. OK for trunk? Thanks, Alex gcc/ChangeLog: PR target/99977 * config/arm/arm.c (arm_split_compare_and_swap): Fix up codegen with negative immediates: ensure we expand cbranchsi4_scratch correctly and ensure we satisfy its constraints. * config/arm/sync.md (@atomic_compare_and_swap_1): Don't attempt to tie two output operands together with constraints; collapse two alternatives. (@atomic_compare_and_swap_1): Likewise. * config/arm/thumb1.md (cbranchsi4_neg_late): New. gcc/testsuite/ChangeLog: PR target/99977 * gcc.target/arm/pr99977.c: New test. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 475fb0d827f..8d19b8a73fd 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -30737,13 +30737,31 @@ arm_split_compare_and_swap (rtx operands[]) } else { - emit_move_insn (neg_bval, const1_rtx); cond = gen_rtx_NE (VOIDmode, rval, oldval); if (thumb1_cmpneg_operand (oldval, SImode)) - emit_unlikely_jump (gen_cbranchsi4_scratch (neg_bval, rval, oldval, - label2, cond)); + { + rtx src = rval; + if (!satisfies_constraint_L (oldval)) + { + gcc_assert (satisfies_constraint_J (oldval)); + + /* For such immediates, ADDS needs the source and destination regs + to be the same. + + Normally this would be handled by RA, but this is all happening + after RA. */ + emit_move_insn (neg_bval, rval); + src = neg_bval; + } + + emit_unlikely_jump (gen_cbranchsi4_neg_late (neg_bval, src, oldval, + label2, cond)); + } else - emit_unlikely_jump (gen_cbranchsi4_insn (cond, rval, oldval, label2)); + { + emit_move_insn (neg_bval, const1_rtx); + emit_unlikely_jump (gen_cbranchsi4_insn (cond, rval, oldval, label2)); + } } arm_emit_store_exclusive (mode, neg_bval, mem, newval, use_release); diff --git a/gcc/config/arm/sync.md b/gcc/config/arm/sync.md index e4682c039b9..b9fa8702606 100644 --- a/gcc/config/arm/sync.md +++ b/gcc/config/arm/sync.md @@ -187,20 +187,20 @@ ;; Constraints of this pattern must be at least as strict as those of the ;; cbranchsi operations in thumb1.md and aim to be as permissive. (define_insn_and_split "@atomic_compare_and_swap_1" - [(set (match_operand:CCSI 0 "cc_register_operand" "=&c,&l,&l,&l") ;; bool out + [(set (match_operand:CCSI 0 "cc_register_operand" "=&c,&l,&l") ;; bool out (unspec_volatile:CCSI [(const_int 0)] VUNSPEC_ATOMIC_CAS)) - (set (match_operand:SI 1 "s_register_operand" "=&r,&l,&0,&l*h") ;; val out + (set (match_operand:SI 1 "s_register_operand" "=&r,&l,&l*h") ;; val out (zero_extend:SI - (match_operand:NARROW 2 "mem_noofs_operand" "+Ua,Ua,Ua,Ua"))) ;; memory + (match_operand:NARROW 2 "mem_noofs_operand" "+Ua,Ua,Ua"))) ;; memory (set (match_dup 2) (unspec_volatile:NARROW - [(match_operand:SI 3 "arm_add_operand" "rIL,lIL*h,J,*r") ;; expected - (match_operand:NARROW 4 "s_register_operand" "r,r,r,r") ;; desired + [(match_operand:SI 3 "arm_add_operand" "rIL,lILJ*h,*r") ;; expected + (match_operand:NARROW 4 "s_register_operand" "r,r,r") ;; desired (match_operand:SI 5 "const_int_operand") ;; is_weak (match_operand:SI 6 "const_int_operand") ;; mod_s (match_operand:SI 7 "const_int_operand")] ;; mod_f VUNSPEC_ATOMIC_CAS)) - (clobber (match_scratch:SI 8 "=&r,X,X,X"))] + (clobber (match_scratch:SI 8 "=&r,X,X"))] "" "#" "&& reload_completed" @@ -209,7 +209,7 @@ arm_split_compare_and_swap (operands); DONE; } - [(set_attr "arch" "32,v8mb,v8mb,v8mb")]) + [(set_attr "arch" "32,v8mb,v8mb")]) (define_mode_attr cas_cmp_operand [(SI "arm_add_operand") (DI "cmpdi_operand")]) @@ -219,19 +219,19 @@ ;; Constraints of this pattern must be at least as strict as those of the ;; cbranchsi operations in thumb1.md and aim to be as permissive. (define_insn_and_split "@atomic_compare_and_swap_1" - [(set (match_operand:CCSI 0 "cc_register_operand" "=&c,&l,&l,&l") ;; bool out + [(set (match_operand:CCSI 0 "cc_register_operand" "=&c,&l,&l") ;; bool out (unspec_volatile:CCSI [(const_int 0)] VUNSPEC_ATOMIC_CAS)) - (set (match_operand:SIDI 1 "s_register_operand" "=&r,&l,&0,&l*h") ;; val out - (match_operand:SIDI 2 "mem_noofs_operand" "+Ua,Ua,Ua,Ua")) ;; memory + (set (match_operand:SIDI 1 "s_register_operand" "=&r,&l,&l*h") ;; val out + (match_operand:SIDI 2 "mem_noofs_operand" "+Ua,Ua,Ua")) ;; memory (set (match_dup 2) (unspec_volatile:SIDI - [(match_operand:SIDI 3 "" ",lIL*h,J,*r") ;; expect - (match_operand:SIDI 4 "s_register_operand" "r,r,r,r") ;; desired + [(match_operand:SIDI 3 "" ",lILJ*h,*r") ;; expect + (match_operand:SIDI 4 "s_register_operand" "r,r,r") ;; desired (match_operand:SI 5 "const_int_operand") ;; is_weak (match_operand:SI 6 "const_int_operand") ;; mod_s (match_operand:SI 7 "const_int_operand")] ;; mod_f VUNSPEC_ATOMIC_CAS)) - (clobber (match_scratch:SI 8 "=&r,X,X,X"))] + (clobber (match_scratch:SI 8 "=&r,X,X"))] "" "#" "&& reload_completed" @@ -240,7 +240,7 @@ arm_split_compare_and_swap (operands); DONE; } - [(set_attr "arch" "32,v8mb,v8mb,v8mb")]) + [(set_attr "arch" "32,v8mb,v8mb")]) (define_insn_and_split "atomic_exchange" [(set (match_operand:QHSD 0 "s_register_operand" "=&r,&r") ;; output diff --git a/gcc/config/arm/thumb1.md b/gcc/config/arm/thumb1.md index c98b59c4fa7..084ed6597e0 100644 --- a/gcc/config/arm/thumb1.md +++ b/gcc/config/arm/thumb1.md @@ -1206,6 +1206,21 @@ (set_attr "type" "multiple")] ) +;; An expander which makes use of the cbranchsi4_scratch insn, but can +;; be used safely after RA. +(define_expand "cbranchsi4_neg_late" + [(parallel [ + (set (pc) (if_then_else + (match_operator 4 "arm_comparison_operator" + [(match_operand:SI 1 "s_register_operand") + (match_operand:SI 2 "thumb1_cmpneg_operand")]) + (label_ref (match_operand 3 "" "")) + (pc))) + (clobber (match_operand:SI 0 "s_register_operand")) + ])] + "TARGET_THUMB1" +) + ;; Changes to the constraints of this pattern must be propagated to those of ;; atomic compare_and_swap splitters in sync.md. These must be at least as ;; strict as the constraints here and aim to be as permissive. diff --git a/gcc/testsuite/gcc.target/arm/pr99977.c b/gcc/testsuite/gcc.target/arm/pr99977.c new file mode 100644 index 00000000000..7911899d928 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pr99977.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-march=armv8-m.base -mfloat-abi=soft -O2" } */ +_Bool f1(int *p) { return __sync_bool_compare_and_swap (p, -1, 2); } +_Bool f2(int *p) { return __sync_bool_compare_and_swap (p, -8, 2); } +int g1(int *p) { return __sync_val_compare_and_swap (p, -1, 2); } +int g2(int *p) { return __sync_val_compare_and_swap (p, -8, 3); }