From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 26E93385DC13; Wed, 14 Feb 2024 19:07:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26E93385DC13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707937625; bh=1Y+LI9k9rRckMj0Fc4iGPlyjQqowoJ6Y3ebT7GSKd9g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kE/9AOjrf5GWo8ALxIeKNrVsKcyNxzz8vSX4waPSKLmbYsnNqXDGPH/ZP3aOhRWtU DrMggFyaxtOJKEdQpRZET8n52SDVDV8qcoqrEn+urd059MpKKdz4vael8D4bxG3ZG9 U/3pv7qd9B2N5AiwZYNrrC2XRmQMdj3c2wLIWHkA= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/113921] Output register of an "asm volatile goto" is incorrectly clobbered/discarded Date: Wed, 14 Feb 2024 19:07:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.4.0 X-Bugzilla-Keywords: inline-asm 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: everconfirmed bug_status cf_reconfirmed_on 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=3D113921 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Last reconfirmed| |2024-02-14 --- Comment #7 from Jakub Jelinek --- So, GCC 11 version: --- gcc/cfgexpand.c.jj 2023-05-09 12:59:04.381738365 +0200 +++ gcc/cfgexpand.c 2024-02-14 19:56:08.733150432 +0100 @@ -3639,7 +3639,16 @@ expand_asm_stmt (gasm *stmt) emit_insn (copy_insn (PATTERN (curr))); rtx_insn *copy =3D get_insns (); end_sequence (); - insert_insn_on_edge (copy, e); + if (rtx_insn *prev =3D e->insns.r) + { + /* Prepend copy before any other previously + inserted insns on the edge rather than append. */ + e->insns.r =3D NULL; + insert_insn_on_edge (copy, e); + insert_insn_on_edge (prev, e); + } + else + insert_insn_on_edge (copy, e); } } } changes the emitted assembler: @@ -7328,7 +7328,7 @@ sync_vmcs02_to_vmcs12: # 0 "" 2 #NO_APP .L1127: - xorl %r12d, %r12d + movq %rax, %r12 .L1083: movq %r12, 240(%rbx) jmp .L1047 @@ -29897,7 +29897,7 @@ nested_vmx_vmexit: # 0 "" 2 #NO_APP .L5187: - xorl %r12d, %r12d + movq %rax, %r12 .L5113: movq %r12, %rdx movl $7, %esi which is I believe exactly what we want. For GCC trunk the patch would be --- gcc/cfgexpand.cc.jj 2024-02-10 11:25:09.995474027 +0100 +++ gcc/cfgexpand.cc 2024-02-14 19:54:30.811505882 +0100 @@ -3687,7 +3687,16 @@ expand_asm_stmt (gasm *stmt) copy =3D get_insns (); end_sequence (); } - insert_insn_on_edge (copy, e); + if (rtx_insn *prev =3D e->insns.r) + { + /* Prepend copy before any other previously + inserted insns on the edge rather than append. */ + e->insns.r =3D NULL; + insert_insn_on_edge (copy, e); + insert_insn_on_edge (prev, e); + } + else + insert_insn_on_edge (copy, e); } } } and with trunk it triggers (I mean the prev !=3D NULL case) only on the nested_vmx_vmexit function and not the other one. Guess one could try to build whole kernel with instrumented gcc (just add FILE *f =3D fopen ("/tmp/asmgoto", "a"); fprintf (f, "%s %s\n", main_input_filename ? main_input_filename : "-", current_function_name ()); fclose (f); next to the e->insns.r =3D NULL; in the patch or so) to find out what else = it affects.=