From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ACEDA3858D35; Fri, 5 Nov 2021 12:55:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACEDA3858D35 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/103066] __sync_val_compare_and_swap/__sync_bool_compare_and_swap aren't optimized Date: Fri, 05 Nov 2021 12:55:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Nov 2021 12:55:10 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103066 --- Comment #6 from Jakub Jelinek --- E.g. the builtin is often used in a loop where the user does his own atomic load first and decides what to do based on that. Say for float f; void foo () { #pragma omp atomic f +=3D 3.0f; } with -O2 -fopenmp we emit: D.2113 =3D &f; D.2115 =3D __atomic_load_4 (D.2113, 0); D.2114 =3D D.2115; : D.2112 =3D VIEW_CONVERT_EXPR(D.2114); _1 =3D D.2112 + 3.0e+0; D.2116 =3D VIEW_CONVERT_EXPR(_1); D.2117 =3D .ATOMIC_COMPARE_EXCHANGE (D.2113, D.2114, D.2116, 4, 0, 0); D.2118 =3D REALPART_EXPR ; D.2119 =3D D.2114; D.2114 =3D D.2118; if (D.2118 !=3D D.2119) goto ; [0.00%] else goto ; [100.00%] : return; which is essentially void foo () { int x =3D __atomic_load_4 ((int *) &f, __ATOMIC_RELAXED), y; float g; do { __builtin_memcpy (&g, &x, 4); g +=3D 3.0f; __builtin_memcpy (&y, &g, 4); } while (!__atomic_compare_exchange_n ((int *) &f, &x, y, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED)); } Can you explain how your proposed change would improve this? It would just slow it down and make it larger.=