Issue 22115 - Optimize if (s.a == 3 ? s : null) to if (s.a == 3)
Summary: Optimize if (s.a == 3 ? s : null) to if (s.a == 3)
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: backend, performance, pull
Depends on:
Blocks:
 
Reported: 2021-07-11 06:50 UTC by Walter Bright
Modified: 2021-07-13 08:44 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2021-07-11 06:50:23 UTC
Currently, dmd often uses the pattern:

    if (e.isAddExp())
        ...

isAddExp(), when inlined, becomes code like:

    if (e.op == TOK.add ? cast(AddExp)this : null)
        ...

This doesn't get optimized to:

    if (e.op == TOK.add)

It should be, in order to make using isAddExp() cost free.
Comment 1 Dlang Bot 2021-07-11 08:09:10 UTC
@WalterBright created dlang/dmd pull request #12860 "fix Issue 22115 - Optimize if (s.a == 3 ? s : null) to if (s.a == 3)" fixing this issue:

- fix Issue 22115 - Optimize if (s.a == 3 ? s : null) to if (s.a == 3)

https://github.com/dlang/dmd/pull/12860
Comment 2 Dlang Bot 2021-07-13 08:44:16 UTC
dlang/dmd pull request #12860 "fix Issue 22115 - Optimize if (s.a == 3 ? s : null) to if (s.a == 3)" was merged into master:

- 60e35e43b097b91b47369fcce863822b4b0bcff8 by Walter Bright:
  fix Issue 22115 - Optimize if (s.a == 3 ? s : null) to if (s.a == 3)

https://github.com/dlang/dmd/pull/12860