patch to bug #86829

Message ID CAEFO=4AiqFvHH5sb1xWguEoSY2osH+NZJzWELkHqefEbgTd_6g@mail.gmail.com
State New
Headers show
Series
  • patch to bug #86829
Related show

Commit Message

Giuliano Augusto Faulin Belinassi Aug. 4, 2018, 1:22 p.m.
Closes bug #86829

Description: Adds substitution rules for both sin(atan(x)) and
cos(atan(x)). These formulas are replaced by x / sqrt(x*x + 1) and 1 /
sqrt(x*x + 1) respectively, providing up to 10x speedup. This identity
can be proved mathematically.

Changelog:

2018-08-03  Giuliano Belinassi <giuliano.belinassi@usp.br>

    * match.pd: add simplification rules to sin(atan(x)) and cos(atan(x)).

Bootstrap and Testing:
There were no unexpected failures in a proper testing in GCC 8.1.0
under a x86_64 running Ubuntu 18.04.
Test run by giulianob on Fri Aug  3 17:01:33 2018
Native configuration is x86_64-pc-linux-gnu

		=== gcc tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/giulianob/Downloads/gcc/src/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.c-torture/compile/compile.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.c-torture/execute/builtins/builtins.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.c-torture/execute/execute.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.c-torture/execute/ieee/ieee.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.c-torture/unsorted/unsorted.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/asan/asan.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/atomic/atomic.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/autopar/autopar.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/charset/charset.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/compat/compat.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/compat/struct-layout-1.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/cpp/cpp.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/cpp/trad/trad.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/debug/debug.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/debug/dwarf2/dwarf2.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/dfp/dfp.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/dg.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/fixed-point/fixed-point.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/format/format.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/goacc-gomp/goacc-gomp.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/goacc/goacc.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/gomp/gomp.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/graphite/graphite.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/guality/guality.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/ipa/ipa.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/lto/lto.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/noncompile/noncompile.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/params/params.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/pch/pch.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/plugin/plugin.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/rtl/rtl.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/sancov/sancov.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/simulate-thread/simulate-thread.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/special/mips-abi.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/special/special.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/sso/sso.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/tls/tls.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/tm/tm.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/torture/dg-torture.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/torture/stackalign/stackalign.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/torture/tls/tls.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/tree-ssa/tree-ssa.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/tsan/tsan.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/ubsan/ubsan.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/vect/costmodel/i386/i386-costmodel-vect.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/vect/costmodel/ppc/ppc-costmodel-vect.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/vect/costmodel/spu/spu-costmodel-vect.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/vect/costmodel/x86_64/x86_64-costmodel-vect.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/vect/vect.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/vmx/vmx.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/vxworks/vxworks.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.dg/weak/weak.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/acker1.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/arm-isr.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/bprob.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/dectest.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/dhry.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/gcov.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/godump.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/help.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/i386-prefetch.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/linkage.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/matrix1.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/mg-2.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/mg.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/options.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/output.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/sieve.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.misc-tests/sort2.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/aarch64/aapcs64/aapcs64.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/aarch64/aarch64.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/aarch64/acle/acle.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/advsimd-intrinsics.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/aarch64/fp16/fp16.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/aarch64/simd/simd.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/aarch64/sve/aarch64-sve.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/alpha/alpha.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/arc/arc.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/arm/aapcs/aapcs.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/arm/acle/acle.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/arm/arm.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/arm/cmse/cmse.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/arm/lto/lto.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/arm/multilib.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/arm/pure-code/pure-code.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/arm/simd/simd.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/avr/avr.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/avr/mmcu/avr-mmcu.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/avr/torture/avr-torture.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/bfin/bfin.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/bfin/builtins/bfin-builtins.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/cris/cris.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/cris/torture/cris-torture.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/epiphany/epiphany.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/frv/frv.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/h8300/h8300.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/hppa/hppa.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/i386/i386.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/i386/iamcu/abi-iamcu.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/i386/math-torture/math-torture.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/i386/mpx/mpx.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/i386/stackalign/stackalign.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/ia64/ia64.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/m68k/m68k.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/microblaze/microblaze.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/mips/inter/mips16-inter.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/mips/mips-nonpic/mips-nonpic.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/mips/mips.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/msp430/msp430.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/nds32/nds32.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/nios2/nios2.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/nvptx/nvptx.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/powerpc/bfp/bfp.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/powerpc/dfp/dfp.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/powerpc/powerpc.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/powerpc/ppc-fortran/ppc-fortran.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/powerpc/vsu/vsu.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/riscv/riscv.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/rl78/rl78.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/rx/rx.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/s390/s390.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/sh/sh.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/sh/torture/sh-torture.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/sparc/sparc.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/spu/ea/ea.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/spu/spu.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/tic6x/builtins/c6x-builtins.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/tic6x/tic6x.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/vax/vax.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/visium/visium.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/x86_64/abi/abi-x86_64.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/x86_64/abi/avx/abi-avx.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/x86_64/abi/avx512f/abi-avx512f.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/x86_64/abi/callabi/callabi.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/ms-sysv.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.target/xstormy16/xstormy16.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gcc.test-framework/test-framework.exp ...
skipping test framework tests, CHECK_TEST_FRAMEWORK is not defined

		=== gcc Summary ===

# of expected passes		134741
# of expected failures		391
# of unsupported tests		2135
/home/giulianob/Downloads/gcc/gcc/xgcc  version 8.1.0 (GCC) 

Test run by giulianob on Fri Aug  3 18:11:07 2018
Native configuration is x86_64-pc-linux-gnu

		=== g++ tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/giulianob/Downloads/gcc/src/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/asan/asan.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/bprob/bprob.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/charset/charset.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/compat/compat.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/compat/struct-layout-1.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/debug/debug.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/debug/dwarf2/dwarf2.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/dfp/dfp.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/dg.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/gcov/gcov.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/goacc-gomp/goacc-gomp.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/goacc/goacc.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/gomp/gomp.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/graphite/graphite.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/guality/guality.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/lto/lto.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/pch/pch.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/plugin/plugin.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/simulate-thread/simulate-thread.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/special/ecos.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/tls/tls.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/tm/tm.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/torture/dg-torture.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/torture/stackalign/stackalign.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/tsan/tsan.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/ubsan/ubsan.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.dg/vect/vect.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.old-deja/old-deja.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/g++.target/aarch64/sve/aarch64-sve.exp ...

		=== g++ Summary ===

# of expected passes		125011
# of expected failures		498
# of unsupported tests		4898
/home/giulianob/Downloads/gcc/gcc/xg++  version 8.1.0 (GCC) 

Test run by giulianob on Fri Aug  3 18:50:55 2018
Native configuration is x86_64-pc-linux-gnu

		=== gfortran tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/giulianob/Downloads/gcc/src/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.dg/coarray/caf.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.dg/debug/debug.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.dg/dg.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.dg/goacc/goacc.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.dg/gomp/gomp.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.dg/graphite/graphite.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.dg/guality/guality.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.dg/ieee/ieee.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.dg/lto/lto.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.dg/prof/prof.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.dg/vect/vect.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.fortran-torture/compile/compile.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/gfortran.fortran-torture/execute/execute.exp ...

		=== gfortran Summary ===

# of expected passes		47161
# of expected failures		83
# of unsupported tests		74
/home/giulianob/Downloads/gcc/gcc/gfortran  version 8.1.0 (GCC) 

Test run by giulianob on Fri Aug  3 19:14:44 2018
Native configuration is x86_64-pc-linux-gnu

		=== objc tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/giulianob/Downloads/gcc/src/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc/compile/compile.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc/execute/exceptions/exceptions.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc/execute/execute.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/attributes/attributes.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/dg.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/gnu-encoding/gnu-encoding.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/lto/lto.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/pch/pch.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/plugin/plugin.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/property/property.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/special/special.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/strings/strings.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/tls/tls.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/torture/dg-torture.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/torture/strings/strings.exp ...
Running /home/giulianob/Downloads/gcc/src/gcc/testsuite/objc.dg/torture/tls/tls.exp ...

		=== objc Summary ===

# of expected passes		2797
# of expected failures		6
# of unsupported tests		68
/home/giulianob/Downloads/gcc/gcc/xgcc  version 8.1.0 (GCC) 

PASS: backtrace_full noinline
PASS: backtrace_full inline
PASS: backtrace_simple noinline
PASS: backtrace_simple inline
PASS: backtrace_syminfo variable
PASS: btest
PASS: stest
PASS: inflate empty
PASS: inflate hello
PASS: inflate goodbye
PASS: inflate ranges
PASS: inflate large
backtrace: 1565689 ns
zlib     : 1593599 ns
ratio    : 1.01783
PASS: ztest
PASS: backtrace_full alloc stress
PASS: edtest
PASS: threaded backtrace_full noinline
PASS: ttest
PASS: backtrace_full noinline
PASS: backtrace_full inline
PASS: backtrace_simple noinline
PASS: backtrace_simple inline
PASS: backtrace_syminfo variable
PASS: ctestg
PASS: backtrace_full noinline
PASS: backtrace_full inline
PASS: backtrace_simple noinline
PASS: backtrace_simple inline
PASS: backtrace_syminfo variable
PASS: ctesta
PASS: backtrace_full noinline
PASS: backtrace_full inline
PASS: backtrace_simple noinline
PASS: backtrace_simple inline
PASS: backtrace_syminfo variable
PASS: dtest
==================
All 8 tests passed
==================
./test-demangle: 995 tests, 0 failures
./test-demangle: 323 tests, 0 failures
./test-demangle: 36 tests, 0 failures
PASS: test-expandargv-0.
PASS: test-expandargv-1.
PASS: test-expandargv-2.
PASS: test-expandargv-3.
PASS: test-expandargv-4.
PASS: test-expandargv-5.
PASS: test-expandargv-6.
PASS: test-strtol-0.
PASS: test-strtol-1.
PASS: test-strtol-2.
PASS: test-strtol-3.
PASS: test-strtol-4.
PASS: test-strtol-5.
PASS: test-strtol-6.
PASS: test-strtol-7.
PASS: test-strtol-8.
PASS: test-strtol-9.
PASS: test-strtol-10.
PASS: test-strtol-11.
PASS: test-strtol-12.
PASS: test-strtol-13.
PASS: test-strtol-14.
PASS: test-strtol-15.
PASS: test-strtol-16.
PASS: test-strtol-17.
PASS: test-strtol-18.
PASS: test-strtol-19.
PASS: test-strtol-20.
Making check in include
Making check in libsupc++
Making check in src
Making check in c++98
Making check in c++11
Making check in filesystem
Making check in doc
Making check in po
Making check in testsuite
Test run by giulianob on Fri Aug  3 19:15:39 2018
Native configuration is x86_64-pc-linux-gnu

		=== libstdc++ tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/giulianob/Downloads/gcc/src/libstdc++-v3/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /home/giulianob/Downloads/gcc/src/libstdc++-v3/testsuite/libstdc++-abi/abi.exp ...
Running /home/giulianob/Downloads/gcc/src/libstdc++-v3/testsuite/libstdc++-dg/conformance.exp ...
Running /home/giulianob/Downloads/gcc/src/libstdc++-v3/testsuite/libstdc++-prettyprinters/prettyprinters.exp ...
Running /home/giulianob/Downloads/gcc/src/libstdc++-v3/testsuite/libstdc++-xmethods/xmethods.exp ...

		=== libstdc++ Summary ===

# of expected passes		12314
# of expected failures		71
# of unsupported tests		571
Making check in python
Making all in include
Making all in libsupc++
Making all in src
Making all in c++98
Making all in c++11
Making all in filesystem
Making all in doc
Making all in po
Making all in testsuite
Making all in python
Making check in sanitizer_common
Making check in interception
Making check in libbacktrace
Making check in lsan
Making check in asan
Making check in ubsan
Making check in tsan
Making all in sanitizer_common
Making all in interception
Making all in libbacktrace
Making all in lsan
Making all in asan
Making all in ubsan
Making check in mpxrt
Making check in mpxwrap
Making all in mpxrt
Making all in mpxwrap
libtool: link: /home/giulianob/Downloads/gcc/./gcc/xgcc -B/home/giulianob/Downloads/gcc/./gcc/ -B/usr/local/x86_64-pc-linux-gnu/bin/ -B/usr/local/x86_64-pc-linux-gnu/lib/ -isystem /usr/local/x86_64-pc-linux-gnu/include -isystem /usr/local/x86_64-pc-linux-gnu/sys-include -funwind-tables -frandom-seed=btest -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute -Wcast-qual -Werror -g -O -g -O2 -o btest btest-btest.o btest-testlib.o  ./.libs/libbacktrace.a -lz
libtool: link: /home/giulianob/Downloads/gcc/./gcc/xgcc -B/home/giulianob/Downloads/gcc/./gcc/ -B/usr/local/x86_64-pc-linux-gnu/bin/ -B/usr/local/x86_64-pc-linux-gnu/lib/ -isystem /usr/local/x86_64-pc-linux-gnu/include -isystem /usr/local/x86_64-pc-linux-gnu/sys-include -funwind-tables -frandom-seed=stest -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute -Wcast-qual -Werror -g -O2 -o stest stest.o  ./.libs/libbacktrace.a -lz
libtool: link: /home/giulianob/Downloads/gcc/./gcc/xgcc -B/home/giulianob/Downloads/gcc/./gcc/ -B/usr/local/x86_64-pc-linux-gnu/bin/ -B/usr/local/x86_64-pc-linux-gnu/lib/ -isystem /usr/local/x86_64-pc-linux-gnu/include -isystem /usr/local/x86_64-pc-linux-gnu/sys-include -DSRCDIR=\"../.././src/libbacktrace\" -g -O2 -o ztest ztest-ztest.o ztest-testlib.o  ./.libs/libbacktrace.a -lz
libtool: link: /home/giulianob/Downloads/gcc/./gcc/xgcc -B/home/giulianob/Downloads/gcc/./gcc/ -B/usr/local/x86_64-pc-linux-gnu/bin/ -B/usr/local/x86_64-pc-linux-gnu/lib/ -isystem /usr/local/x86_64-pc-linux-gnu/include -isystem /usr/local/x86_64-pc-linux-gnu/sys-include -funwind-tables -frandom-seed=edtest -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute -Wcast-qual -Werror -g -O2 -o edtest edtest.o edtest2_build.o testlib.o  ./.libs/libbacktrace.a -lz
libtool: link: /home/giulianob/Downloads/gcc/./gcc/xgcc -B/home/giulianob/Downloads/gcc/./gcc/ -B/usr/local/x86_64-pc-linux-gnu/bin/ -B/usr/local/x86_64-pc-linux-gnu/lib/ -isystem /usr/local/x86_64-pc-linux-gnu/include -isystem /usr/local/x86_64-pc-linux-gnu/sys-include -funwind-tables -frandom-seed=ttest -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute -Wcast-qual -Werror -pthread -g -O2 -o ttest ttest-ttest.o ttest-testlib.o  ./.libs/libbacktrace.a -lz -pthread
libtool: link: /home/giulianob/Downloads/gcc/./gcc/xgcc -B/home/giulianob/Downloads/gcc/./gcc/ -B/usr/local/x86_64-pc-linux-gnu/bin/ -B/usr/local/x86_64-pc-linux-gnu/lib/ -isystem /usr/local/x86_64-pc-linux-gnu/include -isystem /usr/local/x86_64-pc-linux-gnu/sys-include -funwind-tables -frandom-seed=ctestg -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute -Wcast-qual -Werror -g -g -O2 -Wl,--compress-debug-sections=zlib-gnu -o ctestg ctestg-btest.o ctestg-testlib.o  ./.libs/libbacktrace.a -lz
libtool: link: /home/giulianob/Downloads/gcc/./gcc/xgcc -B/home/giulianob/Downloads/gcc/./gcc/ -B/usr/local/x86_64-pc-linux-gnu/bin/ -B/usr/local/x86_64-pc-linux-gnu/lib/ -isystem /usr/local/x86_64-pc-linux-gnu/include -isystem /usr/local/x86_64-pc-linux-gnu/sys-include -funwind-tables -frandom-seed=ctesta -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute -Wcast-qual -Werror -g -g -O2 -Wl,--compress-debug-sections=zlib-gabi -o ctesta ctesta-btest.o ctesta-testlib.o  ./.libs/libbacktrace.a -lz
PASS: backtrace_full noinline
PASS: backtrace_full inline
PASS: backtrace_simple noinline
PASS: backtrace_simple inline
PASS: backtrace_syminfo variable
PASS: btest
PASS: stest
PASS: inflate empty
PASS: inflate hello
PASS: inflate goodbye
PASS: inflate ranges
PASS: inflate large
backtrace: 1568646 ns
zlib     : 1595157 ns
ratio    : 1.0169
PASS: ztest
PASS: backtrace_full alloc stress
PASS: edtest
PASS: threaded backtrace_full noinline
PASS: ttest
PASS: backtrace_full noinline
PASS: backtrace_full inline
PASS: backtrace_simple noinline
PASS: backtrace_simple inline
PASS: backtrace_syminfo variable
PASS: ctestg
PASS: backtrace_full noinline
PASS: backtrace_full inline
PASS: backtrace_simple noinline
PASS: backtrace_simple inline
PASS: backtrace_syminfo variable
PASS: ctesta
==================
All 7 tests passed
==================
Making check in testsuite
Making a new site.exp file...
Test run by giulianob on Fri Aug  3 20:09:06 2018
Native configuration is x86_64-pc-linux-gnu

		=== libgomp tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using ../../.././src/libgomp/testsuite/config/default.exp as tool-and-target-specific interface file.
Running ../../.././src/libgomp/testsuite/libgomp.c/c.exp ...
Running ../../.././src/libgomp/testsuite/libgomp.c++/c++.exp ...
Running ../../.././src/libgomp/testsuite/libgomp.fortran/fortran.exp ...
Running ../../.././src/libgomp/testsuite/libgomp.graphite/graphite.exp ...
Running ../../.././src/libgomp/testsuite/libgomp.hsa.c/c.exp ...
Running ../../.././src/libgomp/testsuite/libgomp.oacc-c/c.exp ...
Running ../../.././src/libgomp/testsuite/libgomp.oacc-c++/c++.exp ...
Running ../../.././src/libgomp/testsuite/libgomp.oacc-fortran/fortran.exp ...

		=== libgomp Summary ===

# of expected passes		5538
# of unsupported tests		290
Making all in testsuite
Making check in testsuite
Making a new site.exp file...
Test run by giulianob on Fri Aug  3 20:15:57 2018
Native configuration is x86_64-pc-linux-gnu

		=== libitm tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using ../../.././src/libitm/testsuite/config/default.exp as tool-and-target-specific interface file.
Running ../../.././src/libitm/testsuite/libitm.c/c.exp ...
Running ../../.././src/libitm/testsuite/libitm.c++/c++.exp ...

		=== libitm Summary ===

# of expected passes		42
# of expected failures		3
# of unsupported tests		1
Making all in testsuite
Making check in testsuite
Making a new site.exp file...
Test run by giulianob on Fri Aug  3 20:16:01 2018
Native configuration is x86_64-pc-linux-gnu

		=== libatomic tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using ../../.././src/libatomic/testsuite/config/default.exp as tool-and-target-specific interface file.
Running ../../.././src/libatomic/testsuite/libatomic.c/c.exp ...

		=== libatomic Summary ===

# of expected passes		54
Making all in testsuite

Comments

Giuliano Augusto Faulin Belinassi Aug. 18, 2018, 12:23 p.m. | #1
ping

On Sat, Aug 4, 2018 at 10:22 AM, Giuliano Augusto Faulin Belinassi
<giuliano.belinassi@usp.br> wrote:
> Closes bug #86829
>
> Description: Adds substitution rules for both sin(atan(x)) and
> cos(atan(x)). These formulas are replaced by x / sqrt(x*x + 1) and 1 /
> sqrt(x*x + 1) respectively, providing up to 10x speedup. This identity
> can be proved mathematically.
>
> Changelog:
>
> 2018-08-03  Giuliano Belinassi <giuliano.belinassi@usp.br>
>
>     * match.pd: add simplification rules to sin(atan(x)) and cos(atan(x)).
>
> Bootstrap and Testing:
> There were no unexpected failures in a proper testing in GCC 8.1.0
> under a x86_64 running Ubuntu 18.04.
Jeff Law Aug. 20, 2018, 7:40 p.m. | #2
On 08/04/2018 07:22 AM, Giuliano Augusto Faulin Belinassi wrote:
> Closes bug #86829
> 
> Description: Adds substitution rules for both sin(atan(x)) and
> cos(atan(x)). These formulas are replaced by x / sqrt(x*x + 1) and 1 /
> sqrt(x*x + 1) respectively, providing up to 10x speedup. This identity
> can be proved mathematically.
> 
> Changelog:
> 
> 2018-08-03  Giuliano Belinassi <giuliano.belinassi@usp.br>
> 
>     * match.pd: add simplification rules to sin(atan(x)) and cos(atan(x)).
> 
> Bootstrap and Testing:
> There were no unexpected failures in a proper testing in GCC 8.1.0
> under a x86_64 running Ubuntu 18.04.
I understand these are mathematical identities.  But floating point
arthmetic in a compiler isn't nearly that clean :-)  We have to worry
about overflows, underflows, rounding, and the simple fact that many
floating point numbers can't be exactly represented.

Just as an example, compare the results for
x = 0x1.fffffffffffffp1023

I think sin(atan (x)) is well defined in that case.  But the x*x isn't
because it overflows.

So  I think this has to be somewhere under the -ffast-math umbrella.
And the testing requirements for that are painful -- you have to verify
it doesn't break the spec benchmark.

I know Richi acked in the PR, but that might have been premature.

jeff
Richard Biener Aug. 21, 2018, 8:02 a.m. | #3
On Mon, Aug 20, 2018 at 9:40 PM Jeff Law <law@redhat.com> wrote:
>
> On 08/04/2018 07:22 AM, Giuliano Augusto Faulin Belinassi wrote:
> > Closes bug #86829
> >
> > Description: Adds substitution rules for both sin(atan(x)) and
> > cos(atan(x)). These formulas are replaced by x / sqrt(x*x + 1) and 1 /
> > sqrt(x*x + 1) respectively, providing up to 10x speedup. This identity
> > can be proved mathematically.
> >
> > Changelog:
> >
> > 2018-08-03  Giuliano Belinassi <giuliano.belinassi@usp.br>
> >
> >     * match.pd: add simplification rules to sin(atan(x)) and cos(atan(x)).
> >
> > Bootstrap and Testing:
> > There were no unexpected failures in a proper testing in GCC 8.1.0
> > under a x86_64 running Ubuntu 18.04.
> I understand these are mathematical identities.  But floating point
> arthmetic in a compiler isn't nearly that clean :-)  We have to worry
> about overflows, underflows, rounding, and the simple fact that many
> floating point numbers can't be exactly represented.
>
> Just as an example, compare the results for
> x = 0x1.fffffffffffffp1023
>
> I think sin(atan (x)) is well defined in that case.  But the x*x isn't
> because it overflows.
>
> So  I think this has to be somewhere under the -ffast-math umbrella.
> And the testing requirements for that are painful -- you have to verify
> it doesn't break the spec benchmark.
>
> I know Richi acked in the PR, but that might have been premature.

It's under the flag_unsafe_math_optimizations umbrella, but sure,
a "proper" way to optimize this would be to further expand
sqrt (x*x + 1) to fabs(x) + ... (extra terms) that are precise enough
and not have this overflow issue.

But yes, I do not find (quickly skimming) other simplifications that
have this kind of overflow issue (in fact I do remember raising
overflow/underflow issues for other patches).

Thus approval withdrawn.

If we had useful range info on floats we might conditionalize such
transforms appropriately.  Or we can enable it on floats and do
the sqrt (x*x + 1) in double.

Richard.

> jeff
>
>
>
Jeff Law Aug. 21, 2018, 2:27 p.m. | #4
On 08/21/2018 02:02 AM, Richard Biener wrote:
> On Mon, Aug 20, 2018 at 9:40 PM Jeff Law <law@redhat.com> wrote:
>>
>> On 08/04/2018 07:22 AM, Giuliano Augusto Faulin Belinassi wrote:
>>> Closes bug #86829
>>>
>>> Description: Adds substitution rules for both sin(atan(x)) and
>>> cos(atan(x)). These formulas are replaced by x / sqrt(x*x + 1) and 1 /
>>> sqrt(x*x + 1) respectively, providing up to 10x speedup. This identity
>>> can be proved mathematically.
>>>
>>> Changelog:
>>>
>>> 2018-08-03  Giuliano Belinassi <giuliano.belinassi@usp.br>
>>>
>>>     * match.pd: add simplification rules to sin(atan(x)) and cos(atan(x)).
>>>
>>> Bootstrap and Testing:
>>> There were no unexpected failures in a proper testing in GCC 8.1.0
>>> under a x86_64 running Ubuntu 18.04.
>> I understand these are mathematical identities.  But floating point
>> arthmetic in a compiler isn't nearly that clean :-)  We have to worry
>> about overflows, underflows, rounding, and the simple fact that many
>> floating point numbers can't be exactly represented.
>>
>> Just as an example, compare the results for
>> x = 0x1.fffffffffffffp1023
>>
>> I think sin(atan (x)) is well defined in that case.  But the x*x isn't
>> because it overflows.
>>
>> So  I think this has to be somewhere under the -ffast-math umbrella.
>> And the testing requirements for that are painful -- you have to verify
>> it doesn't break the spec benchmark.
>>
>> I know Richi acked in the PR, but that might have been premature.
> 
> It's under the flag_unsafe_math_optimizations umbrella, but sure,
> a "proper" way to optimize this would be to further expand
> sqrt (x*x + 1) to fabs(x) + ... (extra terms) that are precise enough
> and not have this overflow issue.
> 
> But yes, I do not find (quickly skimming) other simplifications that
> have this kind of overflow issue (in fact I do remember raising
> overflow/underflow issues for other patches).
> 
> Thus approval withdrawn.
At least until we can do some testing around spec.  There's also a patch
for logarithm addition/subtraction from MCC CS and another from Giuliano
for hyperbolics that need testing with spec.  I think that getting that
testing done anytime between now and stage1 close is sufficient -- none
of the 3 patches is particularly complex.


> 
> If we had useful range info on floats we might conditionalize such
> transforms appropriately.  Or we can enable it on floats and do
> the sqrt (x*x + 1) in double.
Yea.  I keep thinking about what it might take to start doing some light
VRP of floating point objects.  I'd originally been thinking to just
track 0.0 and exceptional value state.  But the more I ponder the more I
think we could use the range information to allow transformations that
are currently guarded by the -ffast-math family of options.

jeff
Giuliano Augusto Faulin Belinassi Aug. 21, 2018, 8:08 p.m. | #5
> Just as an example, compare the results for
> x = 0x1.fffffffffffffp1023

Thank you for your answer and the counterexample. :-)

> If we had useful range info on floats we might conditionalize such
> transforms appropriately.  Or we can enable it on floats and do
> the sqrt (x*x + 1) in double.

I think I managed to find a bound were the transformation can be done
without overflow harm, however I don't know about rounding problems,
however

Suppose we are handling double precision floats for now. The function
x/sqrt(1 + x*x) approaches 1 when x is big enough. How big must be x
for the function be 1?

Since sqrt(1 + x*x) > x when x > 1, then we must find a value to x
that x/sqrt(1 + x*x) < eps, where eps is the biggest double smaller
than 1. Such eps must be around 1 - 2^-53 in ieee double because the
mantissa has 52 bits. Solving for x yields that x must be somewhat
bigger than 6.7e7, so let's take 1e8. Therefore if abs(x) > 1e8, it is
enough to return copysign(1, x). Notice that this arguments is also
valid for x = +-inf (if target supports that) because sin(atan(+-inf))
= +-1, and it can be extended to other floating point formats.The
following test code illustrates my point:
https://pastebin.com/M4G4neLQ

This might still be faster than calculating sin(atan(x)) explicitly.

Please let me know if this is unfeasible. :-)

Giuliano.

On Tue, Aug 21, 2018 at 11:27 AM, Jeff Law <law@redhat.com> wrote:
> On 08/21/2018 02:02 AM, Richard Biener wrote:
>> On Mon, Aug 20, 2018 at 9:40 PM Jeff Law <law@redhat.com> wrote:
>>>
>>> On 08/04/2018 07:22 AM, Giuliano Augusto Faulin Belinassi wrote:
>>>> Closes bug #86829
>>>>
>>>> Description: Adds substitution rules for both sin(atan(x)) and
>>>> cos(atan(x)). These formulas are replaced by x / sqrt(x*x + 1) and 1 /
>>>> sqrt(x*x + 1) respectively, providing up to 10x speedup. This identity
>>>> can be proved mathematically.
>>>>
>>>> Changelog:
>>>>
>>>> 2018-08-03  Giuliano Belinassi <giuliano.belinassi@usp.br>
>>>>
>>>>     * match.pd: add simplification rules to sin(atan(x)) and cos(atan(x)).
>>>>
>>>> Bootstrap and Testing:
>>>> There were no unexpected failures in a proper testing in GCC 8.1.0
>>>> under a x86_64 running Ubuntu 18.04.
>>> I understand these are mathematical identities.  But floating point
>>> arthmetic in a compiler isn't nearly that clean :-)  We have to worry
>>> about overflows, underflows, rounding, and the simple fact that many
>>> floating point numbers can't be exactly represented.
>>>
>>> Just as an example, compare the results for
>>> x = 0x1.fffffffffffffp1023
>>>
>>> I think sin(atan (x)) is well defined in that case.  But the x*x isn't
>>> because it overflows.
>>>
>>> So  I think this has to be somewhere under the -ffast-math umbrella.
>>> And the testing requirements for that are painful -- you have to verify
>>> it doesn't break the spec benchmark.
>>>
>>> I know Richi acked in the PR, but that might have been premature.
>>
>> It's under the flag_unsafe_math_optimizations umbrella, but sure,
>> a "proper" way to optimize this would be to further expand
>> sqrt (x*x + 1) to fabs(x) + ... (extra terms) that are precise enough
>> and not have this overflow issue.
>>
>> But yes, I do not find (quickly skimming) other simplifications that
>> have this kind of overflow issue (in fact I do remember raising
>> overflow/underflow issues for other patches).
>>
>> Thus approval withdrawn.
> At least until we can do some testing around spec.  There's also a patch
> for logarithm addition/subtraction from MCC CS and another from Giuliano
> for hyperbolics that need testing with spec.  I think that getting that
> testing done anytime between now and stage1 close is sufficient -- none
> of the 3 patches is particularly complex.
>
>
>>
>> If we had useful range info on floats we might conditionalize such
>> transforms appropriately.  Or we can enable it on floats and do
>> the sqrt (x*x + 1) in double.
> Yea.  I keep thinking about what it might take to start doing some light
> VRP of floating point objects.  I'd originally been thinking to just
> track 0.0 and exceptional value state.  But the more I ponder the more I
> think we could use the range information to allow transformations that
> are currently guarded by the -ffast-math family of options.
>
> jeff
>
Jeff Law Aug. 21, 2018, 9:27 p.m. | #6
On 08/21/2018 02:08 PM, Giuliano Augusto Faulin Belinassi wrote:
>> Just as an example, compare the results for
>> x = 0x1.fffffffffffffp1023
> 
> Thank you for your answer and the counterexample. :-)
> 
>> If we had useful range info on floats we might conditionalize such
>> transforms appropriately.  Or we can enable it on floats and do
>> the sqrt (x*x + 1) in double.
> 
> I think I managed to find a bound were the transformation can be done
> without overflow harm, however I don't know about rounding problems,
> however
> 
> Suppose we are handling double precision floats for now. The function
> x/sqrt(1 + x*x) approaches 1 when x is big enough. How big must be x
> for the function be 1?
> 
> Since sqrt(1 + x*x) > x when x > 1, then we must find a value to x
> that x/sqrt(1 + x*x) < eps, where eps is the biggest double smaller
> than 1. Such eps must be around 1 - 2^-53 in ieee double because the
> mantissa has 52 bits. Solving for x yields that x must be somewhat
> bigger than 6.7e7, so let's take 1e8. Therefore if abs(x) > 1e8, it is
> enough to return copysign(1, x). Notice that this arguments is also
> valid for x = +-inf (if target supports that) because sin(atan(+-inf))
> = +-1, and it can be extended to other floating point formats.The
> following test code illustrates my point:
> https://pastebin.com/M4G4neLQ
> 
> This might still be faster than calculating sin(atan(x)) explicitly.
> 
> Please let me know if this is unfeasible. :-)
The problem is our VRP implementation doesn't handle any floating point
types at this time.   If we had range information for FP types, then
this kind of analysis is precisely what we'd need to do the
transformation regardless of -ffast-math.
jeff
> 
> Giuliano.
> 
> On Tue, Aug 21, 2018 at 11:27 AM, Jeff Law <law@redhat.com> wrote:
>> On 08/21/2018 02:02 AM, Richard Biener wrote:
>>> On Mon, Aug 20, 2018 at 9:40 PM Jeff Law <law@redhat.com> wrote:
>>>>
>>>> On 08/04/2018 07:22 AM, Giuliano Augusto Faulin Belinassi wrote:
>>>>> Closes bug #86829
>>>>>
>>>>> Description: Adds substitution rules for both sin(atan(x)) and
>>>>> cos(atan(x)). These formulas are replaced by x / sqrt(x*x + 1) and 1 /
>>>>> sqrt(x*x + 1) respectively, providing up to 10x speedup. This identity
>>>>> can be proved mathematically.
>>>>>
>>>>> Changelog:
>>>>>
>>>>> 2018-08-03  Giuliano Belinassi <giuliano.belinassi@usp.br>
>>>>>
>>>>>     * match.pd: add simplification rules to sin(atan(x)) and cos(atan(x)).
>>>>>
>>>>> Bootstrap and Testing:
>>>>> There were no unexpected failures in a proper testing in GCC 8.1.0
>>>>> under a x86_64 running Ubuntu 18.04.
>>>> I understand these are mathematical identities.  But floating point
>>>> arthmetic in a compiler isn't nearly that clean :-)  We have to worry
>>>> about overflows, underflows, rounding, and the simple fact that many
>>>> floating point numbers can't be exactly represented.
>>>>
>>>> Just as an example, compare the results for
>>>> x = 0x1.fffffffffffffp1023
>>>>
>>>> I think sin(atan (x)) is well defined in that case.  But the x*x isn't
>>>> because it overflows.
>>>>
>>>> So  I think this has to be somewhere under the -ffast-math umbrella.
>>>> And the testing requirements for that are painful -- you have to verify
>>>> it doesn't break the spec benchmark.
>>>>
>>>> I know Richi acked in the PR, but that might have been premature.
>>>
>>> It's under the flag_unsafe_math_optimizations umbrella, but sure,
>>> a "proper" way to optimize this would be to further expand
>>> sqrt (x*x + 1) to fabs(x) + ... (extra terms) that are precise enough
>>> and not have this overflow issue.
>>>
>>> But yes, I do not find (quickly skimming) other simplifications that
>>> have this kind of overflow issue (in fact I do remember raising
>>> overflow/underflow issues for other patches).
>>>
>>> Thus approval withdrawn.
>> At least until we can do some testing around spec.  There's also a patch
>> for logarithm addition/subtraction from MCC CS and another from Giuliano
>> for hyperbolics that need testing with spec.  I think that getting that
>> testing done anytime between now and stage1 close is sufficient -- none
>> of the 3 patches is particularly complex.
>>
>>
>>>
>>> If we had useful range info on floats we might conditionalize such
>>> transforms appropriately.  Or we can enable it on floats and do
>>> the sqrt (x*x + 1) in double.
>> Yea.  I keep thinking about what it might take to start doing some light
>> VRP of floating point objects.  I'd originally been thinking to just
>> track 0.0 and exceptional value state.  But the more I ponder the more I
>> think we could use the range information to allow transformations that
>> are currently guarded by the -ffast-math family of options.
>>
>> jeff
>>
Joseph Myers Aug. 21, 2018, 9:49 p.m. | #7
On Tue, 21 Aug 2018, Jeff Law wrote:

> The problem is our VRP implementation doesn't handle any floating point
> types at this time.   If we had range information for FP types, then
> this kind of analysis is precisely what we'd need to do the
> transformation regardless of -ffast-math.

I don't think you can do it regardless of -ffast-math simply because it 
may change the semantics and we've generally assumed that if the 
optimization might produce results different from what you get with 
correctly rounded library functions, it should go under 
-funsafe-math-optimizations.  One might try to figure out a way to split 
that option, to distinguish optimizations that might change correctly 
rounded result but keep errors small from optimizations that might produce 
results that are way off, or spurious exceptions, for some inputs.

Patch

diff -rupN -u gcc_orig/gcc/match.pd gcc_mod/gcc/match.pd
--- gcc_orig/gcc/match.pd	2018-04-20 07:31:23.000000000 -0300
+++ gcc_mod/gcc/match.pd	2018-08-03 15:25:32.307520365 -0300
@@ -4174,6 +4174,25 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        && ! HONOR_INFINITIES (@0))
    (rdiv { build_one_cst (type); } (COS @0))))
 
+ /* Simplify sin(atan(x)) -> x / sqrt(x*x + 1). */
+ (for sins (SIN)
+      atans (ATAN)
+      sqrts (SQRT)
+  (simplify
+   (sins (atans:s @0))
+   (rdiv @0 (sqrts (plus (mult @0 @0) 
+       {build_one_cst (type);})))))
+ 
+ 
+ /* Simplify cos(atan(x)) -> 1 / sqrt(x*x + 1). */
+ (for coss (COS)
+      atans (ATAN)
+      sqrts (SQRT)
+  (simplify
+   (coss (atans:s @0))
+   (rdiv {build_one_cst (type);} 
+       (sqrts (plus (mult @0 @0) {build_one_cst (type);})))))
+
  /* Simplify pow(x,y) * pow(x,z) -> pow(x,y+z). */
  (simplify
   (mult (POW:s @0 @1) (POW:s @0 @2))
diff -rupN -u gcc_orig/gcc/testsuite/gcc.dg/sinatan-1.c gcc_mod/gcc/testsuite/gcc.dg/sinatan-1.c
--- gcc_orig/gcc/testsuite/gcc.dg/sinatan-1.c	1969-12-31 21:00:00.000000000 -0300
+++ gcc_mod/gcc/testsuite/gcc.dg/sinatan-1.c	2018-08-02 19:06:23.632015000 -0300
@@ -0,0 +1,15 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3 -ffast-math -fdump-tree-optimized" } */
+
+extern double sin(double x);
+extern double atan(double x);
+
+double __attribute__ ((noinline)) 
+sinatan_(double x)
+{
+    return sin(atan(x));
+}
+
+/* There should be no calls to sin nor atan */
+/* { dg-final { scan-tree-dump-not "sin " "optimized" } } */
+/* { dg-final { scan-tree-dump-not "atan " "optimized" } } */
diff -rupN -u gcc_orig/gcc/testsuite/gcc.dg/sinatan-2.c gcc_mod/gcc/testsuite/gcc.dg/sinatan-2.c
--- gcc_orig/gcc/testsuite/gcc.dg/sinatan-2.c	1969-12-31 21:00:00.000000000 -0300
+++ gcc_mod/gcc/testsuite/gcc.dg/sinatan-2.c	2018-08-02 19:06:29.579990000 -0300
@@ -0,0 +1,15 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3 -ffast-math -fdump-tree-optimized" } */
+
+extern double cos(double x);
+extern double atan(double x);
+
+double __attribute__ ((noinline)) 
+cosatan_(double x)
+{
+    return cos(atan(x));
+}
+
+/* There should be no calls to sin nor atan */
+/* { dg-final { scan-tree-dump-not "cos " "optimized" } } */
+/* { dg-final { scan-tree-dump-not "atan " "optimized" } } */
diff -rupN -u gcc_orig/gcc/testsuite/gcc.dg/sinatan-3.c gcc_mod/gcc/testsuite/gcc.dg/sinatan-3.c
--- gcc_orig/gcc/testsuite/gcc.dg/sinatan-3.c	1969-12-31 21:00:00.000000000 -0300
+++ gcc_mod/gcc/testsuite/gcc.dg/sinatan-3.c	2018-08-02 19:17:11.663657000 -0300
@@ -0,0 +1,16 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3 -ffast-math -fdump-tree-optimized" } */
+
+extern double sin(double x);
+extern double atan(double x);
+
+double __attribute__ ((noinline)) 
+sinatan_(double x)
+{
+    double atg = atan(x);
+    return sin(atg) + atg;
+}
+
+/* There should be calls to both sin and atan */
+/* { dg-final { scan-tree-dump "sin " "optimized" } } */
+/* { dg-final { scan-tree-dump "atan " "optimized" } } */
diff -rupN -u gcc_orig/gcc/testsuite/gcc.dg/sinatan-4.c gcc_mod/gcc/testsuite/gcc.dg/sinatan-4.c
--- gcc_orig/gcc/testsuite/gcc.dg/sinatan-4.c	1969-12-31 21:00:00.000000000 -0300
+++ gcc_mod/gcc/testsuite/gcc.dg/sinatan-4.c	2018-08-02 19:17:01.091726000 -0300
@@ -0,0 +1,16 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3 -ffast-math -fdump-tree-optimized" } */
+
+extern double cos(double x);
+extern double atan(double x);
+
+double __attribute__ ((noinline)) 
+cosatan_(double x)
+{
+    double atg = atan(x);
+    return cos(atg) + atg;
+}
+
+/* There should be calls to both cos and atan */
+/* { dg-final { scan-tree-dump "cos " "optimized" } } */
+/* { dg-final { scan-tree-dump "atan " "optimized" } } */