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] |
This patch rewrites i387 fptan patterns in order to correctly model load of constant 1.0 into top stack slot. This way, we can get rid of hacky peephole2 patterns that were used to optimize "fptan; fstp0; fld1" sequences into plain fptan. Having new fptan patterns, gcc knows that 1.0 is loaded into top stack slot and uses it according to its generic rules.
double test(double x) { return 1.0 / sqrt (tan(x) + 1.0); }
compiles into (-O2 -ffast-math -fomit-frame-pointer): test: fldl 4(%esp) fptan fadd %st, %st(1) fxch %st(1) fsqrt fdivrp %st, %st(1) ret
This patch also cleans reg-stack.c handling of double-output stack instructions. First part of instruction now uses the same code as normal single-output instruction, while the code to fix-up stack is now part of second-part handling (and simplified considerably). The loading of 1.0 in fptan instruction is handled by generic move code, which was not prepared to load 1.0 into "live" top stack slot (there is an argument for fptan). This case was special-cased in the generic code (with a lenghty comment, why this is necessary).
Patch was bootstrapped and regression tested on i686-pc-linux-gnu for c, c++ and fortran.
* reg-stack.c (subst_stack_regs_pat) [UNSPEC_SINCOS_COS, UNSPEC_XTRACT_FRACT]: Use generic code for instructions that operate on the top of stack. [UNSPEC_SINCOS_SIN, UNSPEC_XTRACT_EXP, UNSPEC_TAN]: Rewrite register handling of instructions that output to the second stack slot. [UNSPEC_TAN_ONE, UNSPEC_TAN_TAN]: Remove. (move_for_stack_reg): Special-case check for dead destination stack slot for constant load of 1.0 inside UNSPEC_TAN.
* config/i386/i386.md (UNSPEC_TAN): New constant. (UNSPEC_TAN_ONE, UNSPEC_TAN_TAN): Remove. (fptanxf4_i387, fptan_extend<mode>xf4_i387): New patterns to correctly model move of constant 1.0 to top stack slot. (*tandf3_1, *tansf3_1, *tanxf3_1): Remove insn patterns. (unnamed peephole2 pattern): Remove corresponding peephole2 pattern that optimizes tan insn and loading of constant 1.0. (tanxf2): Use fptanxf4_i387. (tan<mode>2): Rename from tansf2 and tandf2 and macroize insn patterns using X87MODEF12 mode macro. Use fptan_extend<mode>xf4_i387 and truncate result to requested mode. Use SSE_FLOAT_MODE_P to disable patterns for SSE math. (sincos<mode>3): Use truncxf<mode>2_i387_noop for truncation. (fyl2x_extend<mode>xf3_i387): Use X87MODEF12 for operand 1.
* gcc.target/i386/387-8.c: Update comment about optimizing inherent load of 1.0 of fptan instruction.
Attachment:
i386-tan.c
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |