Bug 22115 – Optimize if (s.a == 3 ? s : null) to if (s.a == 3)

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-07-11T06:50:23Z
Last change time
2021-07-13T08:44:16Z
Keywords
backend, performance, pull
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2021-07-11T06:50:23Z
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 by dlang-bot — 2021-07-11T08:09:10Z
@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 by dlang-bot — 2021-07-13T08:44:16Z
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