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).
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).
Fixed dmd 1.046 and 2.031
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル