[Issue 14436] New: Optimizer fails to remove comparison loop when comparing array against null

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Apr 10 05:21:27 PDT 2015


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

          Issue ID: 14436
           Summary: Optimizer fails to remove comparison loop when
                    comparing array against null
           Product: D
           Version: D1 & D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: performance
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: yebblies at gmail.com

The comparison in this code

int[] arr;
void main()
{
    if (arr != null)
    {
        arr = [1];
    }
}

gets lowered to

!arr.length && !memcmp(arr.ptr, null, arr.length)

The optimizer should be able to tell that the memcmp would always return 0 and
skip the check.

--


More information about the Digitalmars-d-bugs mailing list