Bug 2915 – [Patch]: Optimize -a*-b into a*b

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2009-04-30T02:08:00Z
Last change time
2014-04-18T09:12:05Z
Keywords
patch, performance
Assigned to
bugzilla
Creator
clugdbug

Attachments

IDFilenameSummaryContent-TypeSize
343patch2915.patchPatch against DMD2.029text/plain740

Comments

Comment #0 by clugdbug — 2009-04-30T02:08:03Z
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).
Comment #1 by clugdbug — 2009-04-30T02:11:47Z
Created attachment 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).
Comment #2 by bugzilla — 2009-07-09T02:48:49Z
Fixed dmd 1.046 and 2.031