[Issue 4383] New: Optimizer doesn't keep floating point values on the stack if used more than once

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 24 05:51:04 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4383

           Summary: Optimizer doesn't keep floating point values on the
                    stack if used more than once
           Product: D
           Version: D1 & D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Keywords: performance
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: clugdbug at yahoo.com.au


--- Comment #0 from Don <clugdbug at yahoo.com.au> 2010-06-24 05:51:03 PDT ---
Consider this example code.

int main(string[] args) {
    real x = args.length == 2 ? 6.0 : 4.0; // just to defeat the optimiser
//    real y = x * 2;  // (1)
    real y = x + x;    // (2)
    return cast(int)y;  
}
------------------

After the first line, x is in ST(0). Here's how the compiler calculates y.
Case (1) y = x * 2

            fadd    ST(0),ST

Case (2)  y = x + x
                fstp    tbyte ptr [ESP]  // store x
                fld     tbyte ptr [ESP]  // load x
                fld     tbyte ptr [ESP]  // load x again
                faddp   ST(1),ST

It's very interesting that in the first case, the compiler is able to eliminate
the store of x, yet it doesn't do it in the second case.
The compiler's inability to do this is the primary cause of DMD's poor floating
point performance.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list