[Issue 22115] New: Optimize if (s.a == 3 ? s : null) to if (s.a == 3)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jul 11 06:50:23 UTC 2021


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

          Issue ID: 22115
           Summary: Optimize if (s.a == 3 ? s : null) to if (s.a == 3)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at digitalmars.com

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.

--


More information about the Digitalmars-d-bugs mailing list