From patchwork Tue Sep 26 14:34:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 144916 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1963325vqu; Tue, 26 Sep 2023 07:35:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKf6UD3kdUJJrBRobeeBTyFkK7bHac1XMxo57JJFP2YE7Vh9vBxqssYDKT24PEWRWtLxwp X-Received: by 2002:a05:6402:f20:b0:533:dcb1:5ab4 with SMTP id i32-20020a0564020f2000b00533dcb15ab4mr5368869eda.18.1695738922328; Tue, 26 Sep 2023 07:35:22 -0700 (PDT) Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id m20-20020a50ef14000000b0052f6c71c8f7si11027664eds.443.2023.09.26.07.35.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 07:35:22 -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=@axis.com header.s=selector1 header.b=pDRZmXOp; arc=fail (DNS record missing); 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=axis.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C9353861801 for ; Tue, 26 Sep 2023 14:35:11 +0000 (GMT) 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-he1eur04on2084.outbound.protection.outlook.com [40.107.7.84]) by sourceware.org (Postfix) with ESMTPS id C2C713858439 for ; Tue, 26 Sep 2023 14:34:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2C713858439 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=axis.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=axis.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RJuQmg5M6dPP0JYKqmCLsOnFcF1u8K9SVCghvg4G9OL34t7wPWpW0AEVOVFydjuvtiIZpMWTiYY0LyrN4Pq8x9MdJla5dAIPN3kYfGUNS9yPk9iOll4PKqJg5Hx/4D8f885pmp3Z9iodjoX6otIjbiS4cLaizvtRoEviU7iFl1puGAv91ff7NBRkHvJO5HWwJczc82QrV2G176lTARFLp8uhZHH75P8SFiKKpfOQP493j1dxw9MC7ed8aQvJQJ9DyQ7OH57Lues6VJP8JHo99Wx7kOS/HkM/DfKhfHKbGbSysp8Bbb9h4ek3rjku65AhzV+R5UhlFF6Vdbx2rrTsMQ== 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=v4ivHwOz4K9ngJLn5+tnWfNkhbbBh7u56ew77Usa1L8=; b=NtFTSk39GNoieWG73zyLjNJxfUzPkP49e+GGYvxPAgJicilN7O8byuALUAo0Scw6dv61pl94ibtNsmiCwiSPTgExNthM9MseN5a59IRyAO0HW9n+sNFAlhZWc6WanlO7rilRVNt0d8OhSlyNTIkQ/gjicOp5BlPD5uVL+1iIdp5FFhFESFvk+mds9QV/j3PvrfxK3gdhDE2yqBbGYpjfaqI4OPtSoG4Sna/J7uikuZZcma901p8/axoJC0fcAAowctGzU77Pn+moaKxgRd7aoM26NmFmaCI3QeEG6UfXex0597p0c+4QLCiXYmjSrWSjAf5I+bbjvkbx4KxOdmjtLA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 195.60.68.100) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=axis.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=axis.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v4ivHwOz4K9ngJLn5+tnWfNkhbbBh7u56ew77Usa1L8=; b=pDRZmXOpIj4k2vYL+d8fFXkO7oxp815Edgu8u4uJEVyC7sfq9G0TK6hrLVB/jF5z5gPOUR7khAHKx9n5cZ7OXLWyay102285U9rgtkdKMWyn3GFQgST0h7j7iNN0ZtHa67HJTGAegkW1J3tIDvhzv+SUETvsX7vTVZx1FIK57ls= Received: from DUZPR01CA0060.eurprd01.prod.exchangelabs.com (2603:10a6:10:469::18) by AS8PR02MB9315.eurprd02.prod.outlook.com (2603:10a6:20b:57e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.28; Tue, 26 Sep 2023 14:34:40 +0000 Received: from DB5PEPF00014B9D.eurprd02.prod.outlook.com (2603:10a6:10:469:cafe::d1) by DUZPR01CA0060.outlook.office365.com (2603:10a6:10:469::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.35 via Frontend Transport; Tue, 26 Sep 2023 14:34:40 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 195.60.68.100) smtp.mailfrom=axis.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=axis.com; Received-SPF: Fail (protection.outlook.com: domain of axis.com does not designate 195.60.68.100 as permitted sender) receiver=protection.outlook.com; client-ip=195.60.68.100; helo=mail.axis.com; Received: from mail.axis.com (195.60.68.100) by DB5PEPF00014B9D.mail.protection.outlook.com (10.167.8.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Tue, 26 Sep 2023 14:34:40 +0000 Received: from SE-MAILARCH01W.axis.com (10.20.40.15) by se-mail01w.axis.com (10.20.40.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 26 Sep 2023 16:34:39 +0200 Received: from se-mail01w.axis.com (10.20.40.7) by SE-MAILARCH01W.axis.com (10.20.40.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 26 Sep 2023 16:34:39 +0200 Received: from se-intmail01x.se.axis.com (10.0.5.60) by se-mail01w.axis.com (10.20.40.7) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 26 Sep 2023 16:34:39 +0200 Received: from pchp3.se.axis.com (pchp3.se.axis.com [10.88.21.53]) by se-intmail01x.se.axis.com (Postfix) with ESMTP id BB08F2AD3; Tue, 26 Sep 2023 16:34:39 +0200 (CEST) Received: by pchp3.se.axis.com (Postfix, from userid 171) id B589920431; Tue, 26 Sep 2023 16:34:39 +0200 (CEST) From: Hans-Peter Nilsson To: CC: Subject: [PATCH] __atomic_test_and_set: Fall back to library, not non-atomic code MIME-Version: 1.0 Message-ID: <20230926143439.B589920431@pchp3.se.axis.com> Date: Tue, 26 Sep 2023 16:34:39 +0200 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB5PEPF00014B9D:EE_|AS8PR02MB9315:EE_ X-MS-Office365-Filtering-Correlation-Id: a33ac17b-03cb-4147-6e4d-08dbbe9db7c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ghYS/urrks3SERHHMVUywXDBpc5kiGGvPhbjI12mfhOFCs02EHME2OF7ZnztE22uDgByFXbj+lOjHZIsPmo1wnwL/rEBUBBp9dlDCO/MYCSIba5llqWyahDoBQv6++JtbPY00jf+HpDvSwyoicpdKxHvYtImnSnSMgAR2U9Y39tnqX59KwAti0udKJpS+8Yjx2YRcXHi1Gxp+0krQbh5HpW2ZzrRIEVlF6wu+dqoHXBl9J4oZ4REHMPwyooz383lo9MuCj9zZc704TYtT9Y0CxrBZ46FdjoWEBzYgCD8y/pYKwaLDv1XU8HT0RDVY5rn1UsmJ5pkoLvqvA2wyWmkhpM/8R7ddTIsG8FeMbt5Ub5JdBokH1PDg045dd6cT7bSBe6rBFMPG4zLWsZP88KBa0sXay9PoLnbwDuPTpEKStrtn++PptrGIDmCNN4bTshlcDtwhW82MdY73HYS6SA1CYY3+FFbJujWeBBTnnmEnkKiPpj9yKXsaOrgiyD/CtN03MzIEZCC6gbhSwEDLQrgq5Qxzq26DnKqoKejDRzrRWabB9/X/4tmtAX9Pg8kyCLsP64xYH6nt/YFB5Alt37H+iZiuuFmIiVlEnp8JtCuKswEwgT4Aip9/9kUCqyLu+I1PfpPHZaSf2H9fsBTA3taodQak22E5gzZyIvjHMQsUI299MKmlQt2/GFxj9gRE7wh4IG521a448mvXBp5Q4yMTY29IPxXpO0tzEGgOnmfzAjA0vdttWoRLNPuGeSiN+ANp7o0MB4rpKYh8puz6fshOw== X-Forefront-Antispam-Report: CIP:195.60.68.100; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.axis.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(396003)(39860400002)(376002)(346002)(136003)(230922051799003)(1800799009)(186009)(451199024)(82310400011)(36840700001)(46966006)(40470700004)(26005)(40460700003)(478600001)(336012)(1076003)(426003)(6266002)(356005)(82740400003)(47076005)(33656002)(36860700001)(83380400001)(5660300002)(81166007)(40480700001)(2906002)(4326008)(8936002)(42186006)(8676002)(316002)(41300700001)(70586007)(70206006)(6916009)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: axis.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2023 14:34:40.4416 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a33ac17b-03cb-4147-6e4d-08dbbe9db7c0 X-MS-Exchange-CrossTenant-Id: 78703d3c-b907-432f-b066-88f7af9ca3af X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=78703d3c-b907-432f-b066-88f7af9ca3af; Ip=[195.60.68.100]; Helo=[mail.axis.com] X-MS-Exchange-CrossTenant-AuthSource: DB5PEPF00014B9D.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR02MB9315 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP 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: 1778111136207612361 X-GMAIL-MSGID: 1778111136207612361 Tested cris-elf, native x86_64-pc-linux-gnu and arm-eabi. For arm-eabi, notably lacking any atomic support for the default multilib, with --target_board=arm-sim it regressed 29_atomics/atomic_flag/cons/value_init.cc with the expected linker failure due to lack of __atomic_test_and_set - which is a good thing. With this one, there are 44 unexpected FAILs for libstdc+++ at r14-4210-g94982a6b9cf4. This number was 206 as late as r14-3470-g721f7e2c4e5e, but mitigated by r14-3980-g62b29347c38394, deliberately. To fix the regression, I'll do the same and follow up with adding dg-require-thread-fence on 29_atomics/atomic_flag/cons/value_init.cc (and if approved, commit it before this one). Incidentally, the fortran test-results for arm-eabi are riddled with missing-__sync_synchronize linker errors causing some 18134 unexpected failures, where cris-elf has 121. Ok to commit? -- >8 -- Make __atomic_test_and_set consistent with other __atomic_ and __sync_ builtins: call a matching library function instead of emitting non-atomic code when the target has no direct insn support. There's special-case code handling targetm.atomic_test_and_set_trueval != 1 trying a modified maybe_emit_sync_lock_test_and_set. Previously, if that worked but its matching emit_store_flag_force returned NULL, we'd segfault later on. Now that the caller handles NULL, gcc_assert here instead. While the referenced PR:s are ARM-specific, the issue is general. PR target/107567 PR target/109166 * builtins.cc (expand_builtin) : Handle failure from expand_builtin_atomic_test_and_set. * optabs.cc (expand_atomic_test_and_set): When all attempts fail to generate atomic code through target support, return NULL instead of emitting non-atomic code. Also, for code handling targetm.atomic_test_and_set_trueval != 1, gcc_assert result from calling emit_store_flag_force instead of returning NULL. --- gcc/builtins.cc | 5 ++++- gcc/optabs.cc | 22 +++++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 6e4274bb2a4e..40dfd36a3197 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -8387,7 +8387,10 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode, break; case BUILT_IN_ATOMIC_TEST_AND_SET: - return expand_builtin_atomic_test_and_set (exp, target); + target = expand_builtin_atomic_test_and_set (exp, target); + if (target) + return target; + break; case BUILT_IN_ATOMIC_CLEAR: return expand_builtin_atomic_clear (exp); diff --git a/gcc/optabs.cc b/gcc/optabs.cc index 8b96f23aec05..e1898da22808 100644 --- a/gcc/optabs.cc +++ b/gcc/optabs.cc @@ -7080,25 +7080,17 @@ expand_atomic_test_and_set (rtx target, rtx mem, enum memmodel model) /* Recall that the legacy lock_test_and_set optab was allowed to do magic things with the value 1. Thus we try again without trueval. */ if (!ret && targetm.atomic_test_and_set_trueval != 1) - ret = maybe_emit_sync_lock_test_and_set (subtarget, mem, const1_rtx, model); - - /* Failing all else, assume a single threaded environment and simply - perform the operation. */ - if (!ret) { - /* If the result is ignored skip the move to target. */ - if (subtarget != const0_rtx) - emit_move_insn (subtarget, mem); + ret = maybe_emit_sync_lock_test_and_set (subtarget, mem, const1_rtx, model); - emit_move_insn (mem, trueval); - ret = subtarget; + if (ret) + { + /* Rectify the not-one trueval. */ + ret = emit_store_flag_force (target, NE, ret, const0_rtx, mode, 0, 1); + gcc_assert (ret); + } } - /* Recall that have to return a boolean value; rectify if trueval - is not exactly one. */ - if (targetm.atomic_test_and_set_trueval != 1) - ret = emit_store_flag_force (target, NE, ret, const0_rtx, mode, 0, 1); - return ret; }