From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 559E03858002; Fri, 31 Mar 2023 14:38:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 559E03858002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680273499; bh=O9Dc5DuuTtWBjTcwAJ2PJnGvGnhZ/AU27OEakevHyAQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gKACk0HG/fuSca7XAVG5/WduqDSAfo2/iT5ylFNEAre/iDSiYJj5/Ba3Fwe4nqZLZ OBKEMz1KAwGsOEtTMNV7sBvLB6XPQz+QUMh60H6bHYIUtM8k+dZFuHWYZgmr3Y0IYy ixSVyNbWl0NbMuejMBY5yu0b36BIey70gGAXOfvw= From: "barry.revzin at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109362] codegen adds unnecessary extra add when reading atomic member Date: Fri, 31 Mar 2023 14:38:19 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: barry.revzin at gmail dot com X-Bugzilla-Status: UNCONFIRMED 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109362 --- Comment #1 from Barry Revzin --- Sorry, in this reduced example, it doesn't actually consume an extra regist= er - only rdi is used.=20 In this slightly less reduced example: #include struct S { std::atomic size; std::atomic read_ptr; auto peek() const -> const char* {=20=20=20=20 auto const s =3D size.load(std::memory_order_acquire); return read_ptr.load(std::memory_order_acquire); } }; auto with_atomic(S const& v) { while (true) { if (v.peek()) { return true; } } } the codegen is: with_atomic(WithAtomic const&): lea rdx, [rdi+8] .L2: mov rax, QWORD PTR [rdi] mov rax, QWORD PTR [rdx] test rax, rax je .L2 mov eax, 1 ret which now does consume rdx unnecessarily.=