From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 82E0D3895FE1 for ; Tue, 15 Nov 2022 14:21:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 82E0D3895FE1 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1668522067; bh=b01JcvCRjmD4llUwJ3mFklhH4klFL1/h8NirG75aeSo=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=bC4OKt+fR2h/7wRSDVxQdq03KnEg0mrlc2YLGg6yEDa+vB/QFl1/iNwq7i+ocktTD ZRQXWoio9LRM6baLnGNnzBXpYGVw4R1gvQiSZsXssH/hGBT/74VSaIWRFc2WwxAFf6 Q3se+fPx5HigHQmhFIPtt6fUv1DJw3hWK7xFc5d0= Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 574756677C; Tue, 15 Nov 2022 09:21:05 -0500 (EST) Message-ID: <8039c23568889fe85afbe6940ed625448cf6cd56.camel@xry111.site> Subject: Re: [PATCH] LoongArch: Fix atomic_exchange make comparison and may jump out From: Xi Ruoyao To: Jinyang He , Chenghua Xu , Lulu Cheng Cc: Weining Lu , Xing Li , yala , Peng Fan , gcc-patches@gcc.gnu.org Date: Tue, 15 Nov 2022 22:21:03 +0800 In-Reply-To: <20221115130328.15413-1-hejinyang@loongson.cn> References: <20221115130328.15413-1-hejinyang@loongson.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.0 MIME-Version: 1.0 X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD,GIT_PATCH_0,KAM_SHORT,LIKELY_SPAM_FROM,PDS_OTHER_BAD_TLD,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 List-Id: On Tue, 2022-11-15 at 21:03 +0800, Jinyang He wrote: > gcc/ChangeLog: >=20 > * config/loongarch/sync.md: > Add atomic_cas_value_exchange_and_7 and fix atomic_exchange. nit: * config/loongarch/sync.md (atomic_cas_value_exchange_and_7):=C2=A0 New define_insn. (atomic_exchange): Use atomic_cas_value_exchange_and_7 instead=C2=A0 of atomic_cas_value_cmp_and. > gcc/testsuite/ChangeLog: > > * gcc.target/loongarch/sync-1.c: New test. Likewise, ChangeLog content should be indented with a tab. (Not 8 spaces: if my mail client changes my tab to 8 spaces I'm sorry). /* snip */ > +=C2=A0 return "%G6\\n\\t" > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "1:\\n\\t" > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "ll.\\t%0,%1\\n\\t" > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "and\\t%7,%0,%z3\\n\\t" > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "or%i5\\t%7,%7,%5\\n\\t" > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "sc.\\t%7,%1\\n\\t" > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "beqz\\t%7,1b\\n\\t"; Do we need a "dbar 0x700" after beqz? /* snip */ > diff --git a/gcc/testsuite/gcc.target/loongarch/sync-1.c b/gcc/testsuite/= gcc.target/loongarch/sync-1.c > new file mode 100644 > index 000000000..cebed6a9b > --- /dev/null > +++ b/gcc/testsuite/gcc.target/loongarch/sync-1.c > @@ -0,0 +1,104 @@ > +/* Test __sync_test_and_set in atomic_exchange */ > +/* { dg-do run } */ > +/* { dg-options "-lpthread -std=3Dc11" } */ This test seems not deterministic. And the use of sched_yield is very tricky, as the man page says: sched_yield() is intended for use with real-time scheduling polic= ies (i.e., SCHED_FIFO or SCHED_RR). Use of sched_yield() with nondeterm= in=E2=80=90 istic scheduling policies such as SCHED_OTHER is unspecified and v= ery likely means your application design is broken. I'd suggest to create a bug report at https://gcc.gnu.org/bugzilla and post this test in the PR. Then add the PR number into the changelog, and just add a { dg-do compile } and { dg-final { scan-assembler ... } } test into the testsuite to ensure the correct ll/sc loop is generated. A bug report also emphasises that this is a bug fix, which is suitable for GCC 13 (in stage 3 now) and GCC 12 (the fix will be backported). --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University