public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug d/110359] New: d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435
@ 2023-06-21 18:44 ibuclaw at gcc dot gnu.org
  2023-06-26  1:28 ` [Bug d/110359] " cvs-commit at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: ibuclaw at gcc dot gnu.org @ 2023-06-21 18:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110359

            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 == 0, false))  // 1,2
        return 1;
    if (__builtin_expect(p == 1, false))  // 3,4
        return x;

    double s = x;
    double v = 1;
    for (ulong i = p; i > 1; i >>= 1)     // 5
    {
        v = (i & 0x1) ? s * v : v;
        s = s * s;
    }
    return v * s;
}
---

The first 5 lines of assembly for the above function (corresponding souce line
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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug d/110359] d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435
  2023-06-21 18:44 [Bug d/110359] New: d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435 ibuclaw at gcc dot gnu.org
@ 2023-06-26  1:28 ` cvs-commit at gcc dot gnu.org
  2023-06-26  1:40 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-26  1:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110359

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Iain Buclaw <ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:ab98db1e8c1b997414539f41b7fb814019497d8d

commit r14-2082-gab98db1e8c1b997414539f41b7fb814019497d8d
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Jun 26 03:24:27 2023 +0200

    d: Suboptimal codegen for __builtin_expect(cond, false)

    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.

    This @safe feature is now restricted to just when reading the value of a
    bool field that comes from a union.

            PR d/110359

    gcc/d/ChangeLog:

            * d-convert.cc (convert_for_rvalue): Only apply the @safe boolean
            conversion to boolean fields of a union.
            (convert_for_condition): Call convert_for_rvalue in the default
case.

    gcc/testsuite/ChangeLog:

            * gdc.dg/pr110359.d: New test.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug d/110359] d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435
  2023-06-21 18:44 [Bug d/110359] New: d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435 ibuclaw at gcc dot gnu.org
  2023-06-26  1:28 ` [Bug d/110359] " cvs-commit at gcc dot gnu.org
@ 2023-06-26  1:40 ` cvs-commit at gcc dot gnu.org
  2023-06-26  2:07 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-26  1:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110359

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:9599da719abe4e990fb9cb7ad9d1abc19a5f0429

commit r13-7479-g9599da719abe4e990fb9cb7ad9d1abc19a5f0429
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Jun 26 03:24:27 2023 +0200

    d: Suboptimal codegen for __builtin_expect(cond, false)

    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.

    This @safe feature is now restricted to just when reading the value of a
    bool field that comes from a union.

            PR d/110359

    gcc/d/ChangeLog:

            * d-convert.cc (convert_for_rvalue): Only apply the @safe boolean
            conversion to boolean fields of a union.
            (convert_for_condition): Call convert_for_rvalue in the default
case.

    gcc/testsuite/ChangeLog:

            * gdc.dg/pr110359.d: New test.

    (cherry picked from commit ab98db1e8c1b997414539f41b7fb814019497d8d)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug d/110359] d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435
  2023-06-21 18:44 [Bug d/110359] New: d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435 ibuclaw at gcc dot gnu.org
  2023-06-26  1:28 ` [Bug d/110359] " cvs-commit at gcc dot gnu.org
  2023-06-26  1:40 ` cvs-commit at gcc dot gnu.org
@ 2023-06-26  2:07 ` cvs-commit at gcc dot gnu.org
  2023-06-26  2:09 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-26  2:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110359

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:0f54a73b998b72f7c8452a63730ec3b16fc47854

commit r12-9730-g0f54a73b998b72f7c8452a63730ec3b16fc47854
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Jun 26 03:24:27 2023 +0200

    d: Suboptimal codegen for __builtin_expect(cond, false)

    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.

    This @safe feature is now restricted to just when reading the value of a
    bool field that comes from a union.

            PR d/110359

    gcc/d/ChangeLog:

            * d-convert.cc (convert_for_rvalue): Only apply the @safe boolean
            conversion to boolean fields of a union.
            (convert_for_condition): Call convert_for_rvalue in the default
case.

    gcc/testsuite/ChangeLog:

            * gdc.dg/pr110359.d: New test.

    (cherry picked from commit ab98db1e8c1b997414539f41b7fb814019497d8d)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug d/110359] d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435
  2023-06-21 18:44 [Bug d/110359] New: d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435 ibuclaw at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-06-26  2:07 ` cvs-commit at gcc dot gnu.org
@ 2023-06-26  2:09 ` cvs-commit at gcc dot gnu.org
  2023-06-26  2:10 ` cvs-commit at gcc dot gnu.org
  2023-06-26  2:13 ` ibuclaw at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-26  2:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110359

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:a0c4bd656e0fce16d62877e0eb53ac11b1924d0c

commit r11-10875-ga0c4bd656e0fce16d62877e0eb53ac11b1924d0c
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Jun 26 03:24:27 2023 +0200

    d: Suboptimal codegen for __builtin_expect(cond, false)

    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.

    This @safe feature is now restricted to just when reading the value of a
    bool field that comes from a union.

            PR d/110359

    gcc/d/ChangeLog:

            * d-convert.cc (convert_for_rvalue): Only apply the @safe boolean
            conversion to boolean fields of a union.
            (convert_for_condition): Call convert_for_rvalue in the default
case.

    gcc/testsuite/ChangeLog:

            * gdc.dg/pr110359.d: New test.

    (cherry picked from commit ab98db1e8c1b997414539f41b7fb814019497d8d)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug d/110359] d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435
  2023-06-21 18:44 [Bug d/110359] New: d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435 ibuclaw at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-06-26  2:09 ` cvs-commit at gcc dot gnu.org
@ 2023-06-26  2:10 ` cvs-commit at gcc dot gnu.org
  2023-06-26  2:13 ` ibuclaw at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-26  2:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110359

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:ab134ecb05c6cf1d7a0aee58e7649a93a87c9874

commit r10-11475-gab134ecb05c6cf1d7a0aee58e7649a93a87c9874
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Jun 26 03:24:27 2023 +0200

    d: Suboptimal codegen for __builtin_expect(cond, false)

    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.

    This @safe feature is now restricted to just when reading the value of a
    bool field that comes from a union.

            PR d/110359

    gcc/d/ChangeLog:

            * d-convert.cc (convert_for_rvalue): Only apply the @safe boolean
            conversion to boolean fields of a union.
            (convert_for_condition): Call convert_for_rvalue in the default
case.

    gcc/testsuite/ChangeLog:

            * gdc.dg/pr110359.d: New test.

    (cherry picked from commit ab98db1e8c1b997414539f41b7fb814019497d8d)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug d/110359] d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435
  2023-06-21 18:44 [Bug d/110359] New: d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435 ibuclaw at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-06-26  2:10 ` cvs-commit at gcc dot gnu.org
@ 2023-06-26  2:13 ` ibuclaw at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ibuclaw at gcc dot gnu.org @ 2023-06-26  2:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110359

ibuclaw at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #6 from ibuclaw at gcc dot gnu.org ---
Fix committed.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-06-26  2:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-21 18:44 [Bug d/110359] New: d: Suboptimal codegen for __builtin_expect(cond, false) since PR96435 ibuclaw at gcc dot gnu.org
2023-06-26  1:28 ` [Bug d/110359] " cvs-commit at gcc dot gnu.org
2023-06-26  1:40 ` cvs-commit at gcc dot gnu.org
2023-06-26  2:07 ` cvs-commit at gcc dot gnu.org
2023-06-26  2:09 ` cvs-commit at gcc dot gnu.org
2023-06-26  2:10 ` cvs-commit at gcc dot gnu.org
2023-06-26  2:13 ` ibuclaw at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).