Thread overview
[Issue 2915] New: [Patch]: Optimize -a*-b into a*b
Apr 30, 2009
Apr 30, 2009
Jul 09, 2009
Walter Bright
April 30, 2009

           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

This is a simple patch for a simple optimisation.

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]
                fld     tbyte ptr [ESP]
                sub     ESP,8
                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).


April 30, 2009

------- Comment #1 from  2009-04-30 02:11 -------
Created an attachment (id=343)
 --> (
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).


July 09, 2009

Walter Bright <> changed:

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

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

Configure issuemail:
------- You are receiving this mail because: -------