[Issue 24646] reading a bool generates redundant masking code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jul 3 15:04:27 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24646

Dennis <dkorpel at live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |performance
                 CC|                            |dkorpel at live.nl
            Summary|`is` test broken for        |reading a bool generates
                   |invalid bools               |redundant masking code
           Severity|normal                      |enhancement

--- Comment #2 from Dennis <dkorpel at live.nl> ---
There is no defined behavior for `is` on invalid bools, so you can't say it's
broken when dmd doesn't do a particular thing. It is true that dmd still does
redundant masking for bool from a previous safety fix, which can now be removed
since safe values for `bool` have been agreed upon and specified since, so I'll
reframe this as a performance issue.

This code:
```D
bool eq(bool a, bool b)
{
    return a is b;
}
```

Generates this code with `-O`:
```
mov     CL,SIL
and     CL,1
mov     DL,DIL
and     DL,1
cmp     CL,DL
setz    AL
pop     RBP
```

Which could have the `and` instructions removed.

--


More information about the Digitalmars-d-bugs mailing list