www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4380] New: Poor optimisation of x*x, where x is real

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4380

           Summary: Poor optimisation of x*x, where x is real
           Product: D
           Version: D1 & D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: performance
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: clugdbug yahoo.com.au


--- Comment #0 from Don <clugdbug yahoo.com.au> 2010-06-24 03:02:44 PDT ---
// TEST CASE
int main(string[] args) {
    real x = args.length == 2 ? 6.0 : 4.0; // just to defeat the optimiser
    real y = x*x;
    return cast(int)y;  
}
----

With double x, produces:
                fstp    qword ptr [ESP] // store x
                fld     qword ptr [ESP]
                fmul    ST,ST(0)
Does the same for float x.

With real x, produces                
                fstp    tbyte ptr [ESP] // store x
                fld     tbyte ptr [ESP]
                fld     tbyte ptr [ESP] // Why is it loading this twice???
                fmulp   ST(1),ST

The last two lines should just be fmul ST, ST(0)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 24 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4380


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 24 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4380


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh quickfur.ath.cx


--- Comment #1 from hsteoh quickfur.ath.cx 2013-08-17 12:16:37 PDT ---
This is still happening on git HEAD.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 17 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4380


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com


--- Comment #2 from yebblies <yebblies gmail.com> 2013-08-18 14:02:45 EST ---
In cg87, line 1661 (load87) it has this code:

if ((ty == TYldouble || ty == TYildouble) &&
    op != -1 && e->Eoper != OPd_ld)
    goto Ldefault;

op is 0 here (OPvar), and ty == TYldouble, so all the normal var cse checking
is skipped.


Down at 1887, we have

#if 1           /* Do this instead of codelem() to avoid the freenode(e).
                   We also lose CSE capability  */
                if (e->Eoper == OPconst)
                {
                    c = load87(e, 0, &retregs, NULL, -1);
                }
                else
                    c = (*cdxxx[e->Eoper])(e,&retregs);
#else
                c = codelem(e,&retregs,FALSE);
#endif

So it looks like this was intentional to avoid some kind of compiler internal
bug.  Removing both conditions results in the correct code, but who knows what
else it breaks.

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