From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 567DC3858D35; Wed, 21 Jun 2023 18:45:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 567DC3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687373100; bh=g9WuBqRDFIgGSs60nAia/hgSnPpurL2AiGD9vJzTZBg=; h=From:To:Subject:Date:From; b=L21NzM6ssNHcyMzjYzMeFdW5bO2CQgWO0yBNKSXYJt+ed/FkpZbRNDuw0wlJ3C7/E 6APjKciBJNIcbZyqCGleROsugQcauT5vEcdwnFZDO1SqHbr1nvcitXXHnYxBWkEdZl lffVX4q2kTxvErpwPUbETkBcIsfKbdoKbTpWVFKo= From: "ibuclaw at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug d/110359] New: d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435 Date: Wed, 21 Jun 2023 18:44:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: d X-Bugzilla-Version: 11.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ibuclaw at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ibuclaw at gdcproject dot 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=3D110359 Bug ID: 110359 Summary: d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435 Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: d Assignee: ibuclaw at gdcproject dot org Reporter: ibuclaw at gcc dot gnu.org Target Milestone: --- Since pr96435, both boolean objects *and* expressions have been evaluated in the following way. (*(ubyte*)&obj_or_expr) & 1 It has been noted that sometimes this can cause the back-end to optimize in non-obvious ways - in particular with `__builtin_expect`. --- double pow(in double x, in ulong p) { import gcc.builtins : __builtin_expect; if (__builtin_expect(p =3D=3D 0, false)) // 1,2 return 1; if (__builtin_expect(p =3D=3D 1, false)) // 3,4 return x; double s =3D x; double v =3D 1; for (ulong i =3D p; i > 1; i >>=3D 1) // 5 { v =3D (i & 0x1) ? s * v : v; s =3D s * s; } return v * s; } --- The first 5 lines of assembly for the above function (corresponding souce l= ine marked in comments) --- double example.pow(in double, in ulong): test rdi, rdi je .L6 cmp rdi, 1 je .L1 jbe .L1 --- The jbe condition looks like it is either redundant, or suboptimal. This @safe feature could be restricted to just when reading the value of a = bool field that comes from a union.=