From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60056.outbound.protection.outlook.com [40.107.6.56]) by sourceware.org (Postfix) with ESMTPS id 651D73858D3C for ; Thu, 31 Mar 2022 16:20:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 651D73858D3C Received: from DB8PR09CA0005.eurprd09.prod.outlook.com (2603:10a6:10:a0::18) by AM8PR08MB6531.eurprd08.prod.outlook.com (2603:10a6:20b:355::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.17; Thu, 31 Mar 2022 16:20:24 +0000 Received: from DB5EUR03FT062.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:a0:cafe::8a) by DB8PR09CA0005.outlook.office365.com (2603:10a6:10:a0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.13 via Frontend Transport; Thu, 31 Mar 2022 16:20:24 +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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT062.mail.protection.outlook.com (10.152.20.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.19 via Frontend Transport; Thu, 31 Mar 2022 16:20:23 +0000 Received: ("Tessian outbound 9511859e950a:v118"); Thu, 31 Mar 2022 16:20:23 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 634478ed01fb667c X-CR-MTA-TID: 64aa7808 Received: from 90846e4f2484.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9D54F499-4488-4F7F-A804-03F4E3D4981A.1; Thu, 31 Mar 2022 16:20:16 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 90846e4f2484.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 31 Mar 2022 16:20:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dT+x2W0WfHCgV3eXKzmXZfXirSQiwk99/Fq+rHCEop4DO8KgNoHzJqM4MWlhBXyA0sP9NxsIgGHEDL3sOmoUN+jqIzktU0y+yKhLPwuFA/z04xbTwItNy0oOhDjT0EjnOzcrZ9uMCF/XZs2BHesgdq50KklCG54RsQdDrM7o+fTlEreBpGAMwSgo+T+V8NEdpHUVBcmruQW4cLHybIvrIV+m9lAigixQ0MJMByzAPMwwrr6vddjeLoXeSKifSO9RpT19JTEnoz/BCwO2TGkoHVl7jNlNGuPWDGMJw6VTdE6iRkZN53VGd9ak7A+hqP7LcRDaukviIxzR2IYfTpxZMA== 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=85j8aRgTmr8o4PgI/ENXWhoGsFzk0vV0rITLVI+mNK4=; b=n0fMUb82PV1PdM/2rgJVZjGuyb5JTffxmqCOcjiJDZ0TB8oqDrzMAAj/n7MlHfBRNX8BYfUUuUdAdgIIAuWIuOqpiFC+bPQcywC6miZ1gl/iiEOsNi4jxk5vkBMNn+LwnxMeu47wTtbuHCkjbUZrjndeM3YjwV1j1LVnIT4oQptW5tA2JTWuRsK5oxmEijdNXy0pNjZ1SJ/QQxheEkNXoSUlO/KH+eEKrgevKNgrXE7aW/CtVBFlVsWofrsnOTXZs4ryD3hxQpzQkawzkmhhKRYAq4aocVQUZS5D3HZnxWYolVEaj8vKzxa+ALFRzZaaf3QMRdxxrUMILUBIZAsQfg== 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 PAXPR08MB7201.eurprd08.prod.outlook.com (2603:10a6:102:208::18) by HE1PR08MB2906.eurprd08.prod.outlook.com (2603:10a6:7:38::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.22; Thu, 31 Mar 2022 16:20:13 +0000 Received: from PAXPR08MB7201.eurprd08.prod.outlook.com ([fe80::8467:33e9:2c4b:c7b7]) by PAXPR08MB7201.eurprd08.prod.outlook.com ([fe80::8467:33e9:2c4b:c7b7%7]) with mapi id 15.20.5038.015; Thu, 31 Mar 2022 16:20:13 +0000 Date: Thu, 31 Mar 2022 16:19:59 +0000 From: Alex Coplan To: gcc-patches@gcc.gnu.org Cc: Richard Earnshaw , Kyrylo Tkachov Subject: [PATCH][GCC 9] arm: Fix ICEs with compare-and-swap and -march=armv8-m.base [PR99977] Message-ID: Content-Type: multipart/mixed; boundary="BFG8vOFvEmgu7sC0" Content-Disposition: inline X-ClientProxiedBy: LO4P123CA0489.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1ab::8) To PAXPR08MB7201.eurprd08.prod.outlook.com (2603:10a6:102:208::18) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 21282bd5-db34-4c75-276e-08da13325bc9 X-MS-TrafficTypeDiagnostic: HE1PR08MB2906:EE_|DB5EUR03FT062:EE_|AM8PR08MB6531:EE_ X-Microsoft-Antispam-PRVS: 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: B505Ohjw6ilgPh4wFv6hJjiOAgE4f6fkCfydrMhi351AVEiMXmhGZ2uq6T7Ds3rf/k9Mst8JggPYEliVfhg9OMv3khWdI+yIq/qIU6tTOjNobVIlCKMv4AVXzY3Ow9OwcjredLgmF2ODfedKxdRg7Xas4x0OS87PW5Cje9zJUCfQy/dGzgpiFIGXlzLEk5Wm1cZeLfGMZc8WWvZqGDWzdb/pGmCn2pMwj4NCpWarM0+cPHnj5QiCrZ4haII3vpJ6QBizqlco5ebw2HEiXNjDkgFj61Qhjxi8HjuQHY8msS3hPd1xPJqIuw0tmG4MWbsMS1Su2pyXqm99pYCtu8L0amioArK4CQs3VzNw029trWVLy8EMv9DSpYZPIGT1b/7tgzaeUekVsDmFDq4W3kwspwhPuMcQWx4W4NjVlKfy6k9SL0BHhPLEYvZ1pfAQFnORKD8U6KLcOU0evBfkFc/WtNRDxGsH/3ZxUpBvVmKWbJ/LBAelL2cych2wv9tLQskaUyMuxbI0l8gDbE0kK8O90Lebl0FARBGslQ3zvyyQjlyi6MRgSRhmbYKuabSpJT0f4Foue1zY5mtU6Q9LdsNZw4TawsvKhd7bU9vVeYkObBr9LOKWzuTxO6bBPojULfRsDvVmxj6gBFm5hLeanrRrXEZx58VZSx3pNZSdw8D5dQlRavTiCG/J5OX2m0VVB6p4zcxLT9+dbdHNJ0n+0PBfRGPqg6XtIPYeyKBcPoEyd8hRZKDWU3dFGFwijShyjdMVZKratDTxRHXu1G9fES0jLUHJkVb09oUzmaGbN1MGEQw= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR08MB7201.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(6916009)(54906003)(6666004)(8676002)(66476007)(21480400003)(316002)(2616005)(26005)(84970400001)(66946007)(186003)(4326008)(86362001)(38100700002)(66556008)(6486002)(44144004)(508600001)(6512007)(5660300002)(6506007)(2906002)(235185007)(8936002)(36756003)(44832011)(33964004)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR08MB2906 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: DB5EUR03FT062.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 984abc54-e1f6-4deb-3c4e-08da133255cf X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UStU9lSzLm6864jW5ewip8N8EjC9n9UgJLxw+tTKcaRanbNiFuzDd4KgbMpd+HhCFrH4j5cqHpTaiwdY8E+Y8kiOE79rWkAe1y8d6BFt9JcLMYDr93hgdeZ94jXCESRIhpH1BPCXa/bDTC8hhLrdQcyupIGMuPjAc23RuGrbyXD8t7G4t2lwHBa7srQEKAYN/ZnJRFCXgV5v4ej7RojiBxT+GFkL3ioK2NmbAspWI3ehZ3kjEslHcJ9WOexl5Ct82nsk0OAdyMNdVInCRbCpfUh+9FozeHpc+KLFcIXXHpOx/fFOcVI6TflSKLE9ug896sHdZKXW7PI8Ds/F+dcJEiiv5nFZN8wlVA7ZNlKBOinU2MJ6Kw8p6sSI2zMjDkBFoeoH+q8iRXa+qAyxS3Q+yG9h30nL+2RPMHitK3/i4iRcj3o5dsamvXHyibev18jvIvDXoitdKgeiJ26WhsTEqt2HlrPsr6qDe3i2rqSsCBQDXkzzMlvmMCniI0vXqD1hPZoKlujdjdM57Eb2M0ydJLfIs8VWd+fnqXWnzfNHs3L06hnwr9lSdGuKG+PacJCSWRyezaFTLAyUpwzyu69piXSL7AzKQ/QL4mku8zfG1EPurY9eGEd0zJOh9IOFsaAXhER2x9gZrsNLVJG89IobqNoriAwzflYRx16tEZ6RiM9vPukoD/2Ys4jTQo57AEqFybjA3TvGOFcAqcO01upTuHeDFlNeRNNKuz0hItNBcaxzGX9m7nohifNlVIcz3oULRNXR359qQhFlIx3atEcCs6y6i9AECdh6uj2/xSSI7XY= 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:(13230001)(4636009)(46966006)(36840700001)(40470700004)(235185007)(6666004)(26005)(40460700003)(186003)(336012)(5660300002)(508600001)(36756003)(6506007)(21480400003)(47076005)(44144004)(86362001)(8936002)(33964004)(6916009)(70206006)(316002)(36860700001)(54906003)(356005)(4326008)(84970400001)(82310400004)(8676002)(70586007)(2906002)(6486002)(81166007)(6512007)(44832011)(2616005)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2022 16:20:23.5392 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 21282bd5-db34-4c75-276e-08da13325bc9 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: DB5EUR03FT062.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6531 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Thu, 31 Mar 2022 16:20:44 -0000 --BFG8vOFvEmgu7sC0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Hi, This is a backport of the fix for PR99977 to the GCC 9 branch. The only case where the GCC 10 patch did not apply cleanly was on sync.md, where some of the context has changed, but the substance of the patch has not changed, it simply required applying by hand. Tested as follows: - Bootstrap/regtest on arm-linux-gnueabihf. - Regression tested a cross compiler configured with --with-arch=armv8-m.base. OK for the GCC 9 branch? Thanks, Alex --- 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. 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. --BFG8vOFvEmgu7sC0 Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="patch.txt" diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 58afc4a2647..8cbdb9a44e5 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -29053,13 +29053,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 0e777a92bb4..693a802c292 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 8f051f87c0f..edbeb7340d4 100644 --- a/gcc/config/arm/thumb1.md +++ b/gcc/config/arm/thumb1.md @@ -1242,6 +1242,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..db330e4a4a3 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pr99977.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target arm_arch_v8m_base_ok } */ +/* { dg-options "-O2" } */ +/* { dg-add-options arm_arch_v8m_base } */ +_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); } --BFG8vOFvEmgu7sC0--