This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, i386]: Optimize x87 constants some more


Hello!

Having the patch [1] that fixes float extension of FP constants in the
SVN, we can fix the problems with XFmode constants [2] in a better
way.

Attached patch disables XFmode move patterns for x87 constants (for
!optimize_size), as the splitter, introduced in [1] generates correct
x87 instruction even for float_extended constants. This patch also
enables size optimizations for DFmode and SFmode constants, where it
avoids operators with memory operands, when operand can be loaded by a
special instruction. Patch also tightens constraints for
float_extended XFmode operators (in order to prevent float_extend:XF
(XFreg) ).

Some simple testcases show the benefit of this patch:

a) return fmod (x, 1.0); (the testcase from [2]):

gcc -O2 -ffast-math -fomit-frame-pointer:

       fldl    4(%esp)
       fld1                       <<- x87 constant load
       fxch    %st(1)
.L2:
       fprem
       fnstsw  %ax
       sahf
       jp      .L2
       fstp    %st(1)
       ret

b) return sqrt(x) + 1.0;

gcc -O2 -ffast-math -fomit-frame-pointer:

       fldl    4(%esp)
       fsqrt
       fadds   .LC0    <<- memory operand (faster, but 6 bytes)
       ret

gcc -Os -ffast-math -fomit-frame-pointer:

       fldl    4(%esp)
       fsqrt
       fld1                                 <<- 2 bytes
       faddp   %st, %st(1)      <<- 2 bytes, but together a bit
slower than code above
       ret

c) return exp(x);

gcc -O2 -ffast-math -fomit-frame-pointer:

       fldl2e                      <<- x87 constant load
       fmull   4(%esp)
       fld     %st(0)
       frndint
       fsubr   %st, %st(1)
       fxch    %st(1)
       f2xm1
       fadds   .LC1          <<- actually x + 1.0, inherent float
extend from SFmode
       fscale
       fstp    %st(1)
       ret

d) return -1.0 / tan(x);

gcc -Os -ffast-math -fomit-frame-pointer:

       fldl    4(%esp)
       fptan                        <<- peephole2 removed fld1
       fchs
       fdivp   %st, %st(1)
       ret

2006-11-29 Uros Bizjak <ubizjak@gmail.com>

	* config/i386/i386.md (movsf_1): Enable pattern for standard
	80387 constants before reload when optimizing for size.
	(*movdf_nointeger, *movdf_integer): Ditto.
	(*movxf_nointeger, *movxf_integer): Disable patterns for standard
	80387 constants before reload wheb not optimizing for size.

	(*fop_xf_4_i387, *fop_xf_5_i387, *fop_xf_6_i387): Avoid float
	extension of XFmode input operands.

Patch was bootstrapped on i686-pc-linux-gnu, regression tested for c,
c++ and fortran. OK for mainline?

Uros.

[1] http://gcc.gnu.org/ml/gcc-patches/2006-11/msg01762.html
[2] http://gcc.gnu.org/ml/gcc-patches/2006-11/msg00133.html

Attachment: i386-fpconst.diff
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]