[ was: Re: [Patch][nvptx] return true in libc_has_function for function_sincos ] On 9/26/20 6:47 PM, Tobias Burnus wrote: > Found when looking at PR97203 (but having no effect there). > > The GCC ME optimizes with -O1 (or higher) the >   a = sinf(x) >   b = cosf(x) > to __builtin_cexpi(x, &a, &b) > (...i as in internal; like cexp(z) but with with __real__ z == 0) > > > In expand_builtin_cexpi, that is handles as: >   if (optab_handler (sincos_optab, mode) != CODE_FOR_nothing) >     ... >   else if (targetm.libc_has_function (function_sincos)) >     ... >   else >         fn = builtin_decl_explicit (BUILT_IN_CEXPF); > > And the latter is done. As newlib's cexpf does not know that > __real__ z == 0, it calculates 'r = expf (__real__ z)' before > invoking sinf and cosf on __imag__ z. > > Thus, it is much faster to call 'sincosf', which also exists > in newlib. > > Solution: Return true for targetm.libc_has_function (function_sincos). > > > NOTE: With -funsafe-math-optimizations (-O0 or higher), > sinf/cosf and sincosf invoke .sin.approx/.cos/.approx instead of > doing a library call. This version takes care to enable sincos and sincosf, but not sincosl. Target hook changes OK for trunk? Thanks, - Tom