www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2915] New: [Patch]: Optimize -a*-b into a*b

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

           Summary: [Patch]: Optimize -a*-b into a*b
           Product: D
           Version: 1.043
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: patch, performance
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: clugdbug yahoo.com.au


This is a simple patch for a simple optimisation.

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;  
}
--
From existing DMD, y=-x*-x is:
                fld     tbyte ptr [ESP]
                fchs
                fld     tbyte ptr [ESP]
                sub     ESP,8
                fchs
                fmulp   ST(1),ST
With patch:
                fld     tbyte ptr [ESP]
                fld     tbyte ptr [ESP]
                fmulp   ST(1),ST
                sub     ESP,8

It's not a huge win, but it's a move in the right direction.
(You can see several other problems with the optimiser in this code. The second
load of x is unnecessary, it should just be fmul ST(0), ST; And the first load
is unnecessary since x was in ST(0) before the start of this code. Which means
the store of y was also unnecessary. This therefore takes us from 6
instructions to 4; optimal is one instruction).


-- 
Apr 30 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2915





------- Comment #1 from clugdbug yahoo.com.au  2009-04-30 02:11 -------
Created an attachment (id=343)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=343&action=view)
Patch against DMD2.029

Applies to integer, real, complex and imaginary types. Causes no FP problems
because change of sign is an exact operation (no rounding ever occurs).


-- 
Apr 30 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2915


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




--- Comment #2 from Walter Bright <bugzilla digitalmars.com>  2009-07-09
02:48:49 PDT ---
Fixed dmd 1.046 and 2.031

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