d: Suboptimal codegen for __builtin_expect(cond, false)
commitab98db1e8c1b997414539f41b7fb814019497d8d
authorIain Buclaw <ibuclaw@gdcproject.org>
Mon, 26 Jun 2023 01:24:27 +0000 (26 03:24 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Mon, 26 Jun 2023 01:26:22 +0000 (26 03:26 +0200)
tree8d9ff30f938173dc164d56a95ae7dd27a356d7ea
parentf445b42e1881fe875c61ad8f7aa080121dd89ab3
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.
gcc/d/d-convert.cc
gcc/testsuite/gdc.dg/pr110359.d [new file with mode: 0644]