On Mon, 18 Oct 2021, Prathamesh Kulkarni wrote: > On Mon, 18 Oct 2021 at 16:18, Richard Biener <rguent...@suse.de> wrote: > > > > On Mon, 18 Oct 2021, Prathamesh Kulkarni wrote: > > > > > Hi Richard, > > > As suggested in PR, I have attached WIP patch that adds two patterns > > > to match.pd: > > > erfc(x) --> 1 - erf(x) if canonicalize_math_p() and, > > > 1 - erf(x) --> erfc(x) if !canonicalize_math_p(). > > > > > > This works to remove call to erfc for the following test: > > > double f(double x) > > > { > > > double g(double, double); > > > > > > double t1 = __builtin_erf (x); > > > double t2 = __builtin_erfc (x); > > > return g(t1, t2); > > > } > > > > > > with .optimized dump shows: > > > t1_2 = __builtin_erf (x_1(D)); > > > t2_3 = 1.0e+0 - t1_2; > > > > > > However, for the following test: > > > double f(double x) > > > { > > > double g(double, double); > > > > > > double t1 = __builtin_erfc (x); > > > return t1; > > > } > > > > > > It canonicalizes erfc(x) to 1 - erf(x), but does not transform 1 - > > > erf(x) to erfc(x) again > > > post canonicalization. > > > -fdump-tree-folding shows that 1 - erf(x) --> erfc(x) gets applied, > > > but then it tries to > > > resimplify erfc(x), which fails post canonicalization. So we end up > > > with erfc(x) transformed to > > > 1 - erf(x) in .optimized dump, which I suppose isn't ideal. > > > Could you suggest how to proceed ? > > > > I applied your patch manually and it does the intended > > simplifications so I wonder what I am missing? > Would it be OK to always fold erfc(x) -> 1 - erf(x) even when there's > no erf(x) in the source ?
I do think it's reasonable to expect erfc to be available when erf is and vice versa but note both are C99 specified functions (either requires -lm). Richard. > So for the following test: > double f(double x) > { > t1 = __builtin_erfc(x) > return t1; > } > > .optimized dump shows: > double f (double x) > { > double t1; > double _2; > > <bb 2> [local count: 1073741824]: > _2 = __builtin_erf (x_1(D)); > t1_3 = 1.0e+0 - _2; > return t1_3; > } > > while before patch, it has: > t1_4 = __builtin_erfc (x_2(D)); [tail call] > return t1_4; > > Thanks, > Prathamesh > > > > > Richard. > > > > > Thanks, > > > Prathamesh > > > > > > > -- > > Richard Biener <rguent...@suse.de> > > SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, > > Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg) > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)