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

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2915 - [Patch]: Optimize -a*-b into a*b
Summary: [Patch]: Optimize -a*-b into a*b
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 enhancement
Assignee: Walter Bright
URL:
Keywords: patch, performance
Depends on:
Blocks:
Reported: 2009年04月30日 02:08 UTC by Don
Modified: 2014年04月18日 09:12 UTC (History)
0 users

See Also:


Attachments
Patch against DMD2.029 (740 bytes, patch)
2009年04月30日 02:11 UTC, Don
Details | Diff
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2009年04月30日 02:08:03 UTC
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 Don 2009年04月30日 02:11:47 UTC
Created attachment 343 [details] 
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 Walter Bright 2009年07月09日 02:48:49 UTC
Fixed dmd 1.046 and 2.031


AltStyle によって変換されたページ (->オリジナル) /