From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 8075D3858C50 for ; Tue, 3 Oct 2023 13:20:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8075D3858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-9adca291f99so158917066b.2 for ; Tue, 03 Oct 2023 06:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696339250; x=1696944050; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=prcqgrzXf6wTuSBWQTSy19Nlf7BBPRC0yZMtL5X15R4=; b=bPprk5ffHhCu5YnlAXeXI1ZeMMS7FM5ge16wh3ZDKb2ui3vRVkdtzgHinkuk+XgqP7 bnd16zIFa8aP8HNs4K5yZCMczGkntmfNV6x82OHwVVFwzADura+eDqtQpVe9xofkISxQ aRCHvGwFes1ZsP4Hfv/OC2OktE5y+BuKdjHuiXkQOWMSyg0JUZ+Kfsu72RORAuTHE+VR 1OM6cOxQQxHGZN9Jph0P9PREW6zCFAUAWQB8/sXTshpZN0cNzabem+f+FcOOD+6h4p1f E7k24lbEdFmljIggb5aHlWfPsvmRR8z1Pi0kxExBEcCDRGPVOUyp85V7jG8D6wsCMO0M /h1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696339250; x=1696944050; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=prcqgrzXf6wTuSBWQTSy19Nlf7BBPRC0yZMtL5X15R4=; b=m1B+pqWldXJSS4ALKmFbWi/LmMQnTIjvz32Du/SL311OSeN+A7c9Yi9clOUacVrekq PHBQDhAp+/wiD6q04SKSHKLPCdBHG22sz7Ea3bA8TbdCJIdN6FUKtkiqLK9YwRDMkyvy AkrnA3E2V6YzxkS8/aIT5i3nlVsBx6kDulzMMWFCxGNOhWW6rA1IQEApCEsXSYKvi/rP E9J634SETjBrcRmrGIgz7boK9Vesn3rmlYyJ20TeX6U3DVo3SRxwl7ua9NGBHaGnvxjt V7to7ooaDj4QBD7SNDeqdxXYNdlcfOWFIHWbHeQHB1J443//9LRwrWhocII1OCzjBhtp ClpA== X-Gm-Message-State: AOJu0YzgTB9+uYTXX4uVjwk3fe+H3h/1j0hoBqZafx77NeJzlcBV1KA+ kKA5fbFAcXOxZjpVLkDFyKP6zQo2iY0y2U6vUs+lTIFKPaGtXc7eqB5Rgw== X-Google-Smtp-Source: AGHT+IEjHUIaf9GAn6wQJO0QAKs3bS4YJpMVqwrUTEVrC8tBgQuFxDrXPu266QvNv5Zzs7DIYU56N6aFIrG0Ts/Ixc4= X-Received: by 2002:a17:906:845a:b0:9a9:f14a:22fa with SMTP id e26-20020a170906845a00b009a9f14a22famr13743308ejy.16.1696339250142; Tue, 03 Oct 2023 06:20:50 -0700 (PDT) MIME-Version: 1.0 References: <20230926143439.B589920431@pchp3.se.axis.com> In-Reply-To: <20230926143439.B589920431@pchp3.se.axis.com> From: Christophe Lyon Date: Tue, 3 Oct 2023 15:20:39 +0200 Message-ID: Subject: Re: [PATCH] __atomic_test_and_set: Fall back to library, not non-atomic code To: Hans-Peter Nilsson Cc: gcc-patches@gcc.gnu.org Content-Type: multipart/alternative; boundary="0000000000006c8f6d0606cfc215" X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 List-Id: --0000000000006c8f6d0606cfc215 Content-Type: text/plain; charset="UTF-8" Hi! On Tue, 26 Sept 2023 at 16:34, Hans-Peter Nilsson wrote: > 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. > > The patch passed almost all our CI configurations, except arm-eabi when testing with -mthumb/-march=armv6s-m/-mtune=cortex-m0/-mfloat-abi=soft/-mfpu=auto where is causes these failures: FAIL: 29_atomics/atomic_flag/clear/1.cc -std=gnu++17 (test for excess errors) UNRESOLVED: 29_atomics/atomic_flag/clear/1.cc -std=gnu++17 compilation failed to produce executable FAIL: 29_atomics/atomic_flag/cons/value_init.cc -std=gnu++20 (test for excess errors) UNRESOLVED: 29_atomics/atomic_flag/cons/value_init.cc -std=gnu++20 compilation failed to produce executable FAIL: 29_atomics/atomic_flag/cons/value_init.cc -std=gnu++26 (test for excess errors) UNRESOLVED: 29_atomics/atomic_flag/cons/value_init.cc -std=gnu++26 compilation failed to produce executable FAIL: 29_atomics/atomic_flag/test_and_set/explicit.cc -std=gnu++17 (test for excess errors) UNRESOLVED: 29_atomics/atomic_flag/test_and_set/explicit.cc -std=gnu++17 compilation failed to produce executable FAIL: 29_atomics/atomic_flag/test_and_set/implicit.cc -std=gnu++17 (test for excess errors) UNRESOLVED: 29_atomics/atomic_flag/test_and_set/implicit.cc -std=gnu++17 compilation failed to produce executable The linker error is: undefined reference to `__atomic_test_and_set' Maybe we need a new variant of dg-require-thread-fence ? Thanks, Christophe 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; > } > > -- > 2.30.2 > > --0000000000006c8f6d0606cfc215--