[PATCH, i386]: Rewrite x87 sqrt patterns, take 2

Uros Bizjak ubizjak@gmail.com
Wed Nov 22 20:23:00 GMT 2006

Geert Bosch wrote:

> Just to add my two cents, I completely agree that __builtin_sqrt  
> returning
> a more precise result than sqrt is acceptable and even expected.
> The same thing happens when inlining functions or using other  
> optimizations:
> values that were previously truncated by storing them to memory may now
> be kept in registers.
> Same reasoning goes for other builtins, like fmod.
> If people really don't want builtins to be used, they can always
> the appropriate GCC option for that, like -fno-builtin-sqrt or
> maybe even -fno-builtin.

Thanks everybody for their comments. If more precise result of a builtin 
is acceptable, then fmod x87 builtin should be changed.

Attached patch introduces new insn patterns that implements no-op 
truncation via UNSPEC. UNSPEC implementation is necessary in order to 
prevent any optimization to simplify real reg->mem->reg x87 truncation 
into a no-op, and to distinguish it from -ffast-math no-op truncation 
(it is expected that -ffast-math optimizes to as many no-op truncations 
as possible in x87 case).
The asm code, generated for the fsqrt testcase in my previous post is 
now the same as without patch. In addition, fmod patterns were changed 
to use no-op truncation, to be consistent with sqrt expanders.

Patch was bootstrapped on x86_64-linux-gnu, regression test is in 
progress. OK for mainline if it passes?

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

        config/i386/i386.md (UNSPEC_TRUNC_NOOP): New unspec definition.
        (truncxfsf2_i387_noop_unspec, truncxfsf2_i387_noop_unspec):
        New insn patterns.
        (sqrtsf2): For !TARGET_SSE_MATH extend SFmode
        operand 1 to XFmode, emit sqrtxf2 insn and truncate result back
        to SFmode using noop truncation.
        (sqrtdf2): Similar for DFmode operands.
        (*sqrtsf2_mixed, *sqrtsf2_i387, *sqrtdf2_mixed, *sqrtdf2_i387)
        (*sqrtextendsfdf2_i387, *sqrtextendsfxf2_i387)
        (*sqrtextenddfxf2_i387): Remove insn patterns.

        (fmodsf3, fmoddf3, remaindersf3, remainderdf3): Use noop
        truncation patterns.

        reg-stack.c (get_true_reg): Handle UNSPEC_TRUNC_NOOP.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: i386-sqrt-2.diff
Type: text/x-patch
Size: 7815 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20061122/3b19f156/attachment.bin>

More information about the Gcc-patches mailing list