From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 42BAD385700A; Thu, 16 Jul 2020 07:05:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42BAD385700A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1594883152; bh=Ijdh6o6Bjvc6xcs9FD+eN7i/f89eosV0a3lUsCajVbI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HjmpM+KnVq/yaPODorUms0KfLzSZfvWXEEutaar0jy3YHCEChSvD4kqh1su1C86zP 3veRm1Lc0NKD+12622sYQkbd+sPnofq4SbyxfYAxqKh8QxgP1ZnJu8R38WqcXxN6wv V2jJ9eLXtuD2OadbeLwagxFRaxRdHRseqpWhwl+A= From: "ubizjak at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/96189] Failure to use eflags from cmpxchg on x86 Date: Thu, 16 Jul 2020 07:05:52 +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: 11.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: ubizjak at gmail dot com X-Bugzilla-Status: REOPENED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ubizjak at gmail dot com X-Bugzilla-Target-Milestone: 11.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc bug_status resolution 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: Thu, 16 Jul 2020 07:05:52 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96189 Uro=C5=A1 Bizjak changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org, | |rguenth at gcc dot gnu.org Status|RESOLVED |REOPENED Resolution|FIXED |--- --- Comment #5 from Uro=C5=A1 Bizjak --- Hm... Please note that peephole2 scanning require exact RTL sequences, and already fails for e.g.: _Bool foo (unsigned int *x, unsigned int z) { unsigned int y =3D 0; __atomic_compare_exchange_n (x, &y, z, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return y =3D=3D 0; } (which is used in a couple of places throughout glibc), due to early peepho= le2 optimization that converts: (insn 7 4 8 2 (set (reg:SI 0 ax [90]) (const_int 0 [0])) "cmpx0.c":5:3 75 {*movsi_internal} to: (insn 31 4 8 2 (parallel [ (set (reg:DI 0 ax [90]) (const_int 0 [0])) (clobber (reg:CC 17 flags)) Other than that, the required sequence is broken quite often by various reloads, due to the complexity of CMPXCHG insn. However, __atomic_compare_exchange_n returns a boolean value that is exactly what the first function is testing, so the following two functions are equivalent: --cut here-- _Bool foo (unsigned int *x, unsigned int y, unsigned int z) { unsigned int old_y =3D y; __atomic_compare_exchange_n (x, &y, z, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return y =3D=3D old_y; } _Bool bar (unsigned int *x, unsigned int y, unsigned int z) { return __atomic_compare_exchange_n (x, &y, z, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); } --cut here-- I wonder, if the above transformation can happen on the tree level, so it w= ould apply universally for all targets, and would also handle CMPXCHG[8,16]B doubleword instructions on x86 targets. Let's ask experts.=