[PATCH] Add pass to CSE sin (x) and cos (x) to sincos (x)
Richard Guenther
rguenther@suse.de
Fri Jan 19 15:18:00 GMT 2007
On Fri, 19 Jan 2007, Uros Bizjak wrote:
> Hello Richard!
>
> > This is the revised patch I am going to commit after a few days of
> > no further objection.
>
> > 2006-12-27 Richard Guenther <rguenther@suse.de>
>
> > PR tree-optimization/30028
> > * tree-ssa-math-opts.c (maybe_record_sincos): New static helper
> > function.
> > (execute_cse_sincos_1): Likewise.
>
> For some reason your patch misses transformation for the testcase below:
>
> --cut here--
> typedef struct cmplx { double x,y; } CMPLX;
>
> void Complex_Sin (CMPLX *target, CMPLX *source)
> {
> target->x = sin(source->x) * cosh(source->y);
> target->y = cos(source->x) * sinh(source->y);
> } /* End Complex_Sin() */
The reason is aliasing. The store to target->x aliases source->x,
so we cannot prove that the arguments to sin and cos are the same.
Also you need to provide -fno-math-errno, as appearantly cosh/sinh
otherwise force clobbering of global memory:
# VUSE <SMT.4_13(D)>
D.1519_2 = source_1(D)->x;
D.1520_3 = sin (D.1519_2);
# VUSE <SMT.4_13(D)>
D.1521_4 = source_1(D)->y;
# SMT.4_14 = VDEF <SMT.4_13(D)>
D.1522_5 = cosh (D.1521_4);
which is because cosh may raise a range error through errno for
too large argument:
DEF_LIB_BUILTIN (BUILT_IN_COSH, "cosh", BT_FN_DOUBLE_DOUBLE,
ATTR_MATHFN_FPROUNDING_ERRNO)
Richard.
> --cut here--
>
> .sincos tree dump says:
>
> Complex_Sin (target, source)
> {
> double D.1627;
> double D.1626;
> double D.1625;
> double D.1624;
> double D.1623;
> double D.1622;
> double D.1621;
> double D.1620;
>
> <bb 2>:
> D.1620_2 = source_1(D)->x;
> D.1621_3 = sin (D.1620_2);
> D.1622_4 = source_1(D)->y;
> D.1623_5 = cosh (D.1622_4);
> D.1624_6 = D.1621_3 * D.1623_5;
> target_7(D)->x = D.1624_6;
> D.1620_8 = source_1(D)->x;
> D.1625_9 = cos (D.1620_8);
> D.1622_10 = source_1(D)->y;
> D.1626_11 = sinh (D.1622_10);
> D.1627_12 = D.1625_9 * D.1626_11;
> target_7(D)->y = D.1627_12;
> return;
>
> }
>
> Uros.
>
>
>
--
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
More information about the Gcc-patches
mailing list