From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 11E863858C53; Wed, 12 Apr 2023 08:54:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11E863858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681289674; bh=XBsWifCDVQ3DDCvoZPIJ5UfjzkSwoKR1Nm5iX6Cw3m0=; h=From:To:Subject:Date:From; b=pRwST2uyB9hkIZkKYlSok8hMBCH2aZkmH4VUPPjBxhCBhZjRDm29Ol+1GotIRIkrC 1k5pK49IQDkrDXkIWnF/kKC3pa1J30Riu9/g1KGFYWABZzcDueQ3LjSWgeS4GOnJY0 4QP8WwG+0NzOSLXZcOs4AT1CfXCpUyQiHnLQ2vjE= From: "ubizjak at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/109483] New: Unoptimal jump threading with assembler flag output Date: Wed, 12 Apr 2023 08:54:33 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ubizjak 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D109483 Bug ID: 109483 Summary: Unoptimal jump threading with assembler flag output Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: ubizjak at gmail dot com Target Milestone: --- Following testcase (int3 mnemonic is for marker only): --cut here-- _Bool foo (int cnt) { if (cnt =3D=3D -1) { _Bool success; asm volatile("int3" : "=3D@ccz" (success)); if (!success) return 0; } asm volatile ("" ::: "memory"); return 1; } --cut here-- compiles w/ -O2 on x86_64 to: 0000000000000000 : 0: 83 ff ff cmp $0xffffffff,%edi 3: 74 0b je 10 5: b8 01 00 00 00 mov $0x1,%eax a: c3 retq=20=20=20 b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 10: cc int3=20=20=20 11: 0f 94 c0 sete %al 14: 74 ef je 5 16: c3 retq=20=20=20 Please note setting of %al before conditional jump. The instruction could be moved after the jump, where the register could be cleared using "xor %eax, %eax", similar to what clang creates: 0000000000000000 : 0: 83 ff ff cmp $0xffffffff,%edi 3: 75 06 jne b 5: cc int3=20=20=20 6: 74 03 je b 8: 31 c0 xor %eax,%eax a: c3 retq=20=20=20 b: b0 01 mov $0x1,%al d: c3 retq=20=20=20 Also note that for ZF=3D1 gcc sets %al to 1, jumps to *5 where the register= is again set to 1. This is not the case in the clang code.=