On Mon, 31 Mar 2025, Jakub Jelinek wrote: > On Mon, Mar 31, 2025 at 11:12:45AM +0200, Richard Biener wrote: > > The following disables tail recursion optimization when fixed-point > > types are involved as we cannot generate -1 for all fixed-point > > types. > > > > Bootstrapped and tested on x86_64-unknown-linux-gnu. OK? > > > > Thanks, > > Richard. > > > > PR tree-optimization/119532 > > * tree-tailcall.cc (process_assignment): FAIL for fixed-point > > typed functions. > > > > * gcc.dg/torture/pr119532.c: New testcase. > > So shouldn't we punt in that case just for the problematic operations > (i.e. NEGATE_EXPR and MINUS_EXPR)? > Aren't the others ok as is?
We are associating the expression which at least breaks with saturating fixed-point. We are also rejecting FP types without -fassociative-math, not trying to special cases some maybe working cases. So, I'm not sure the code behaves correctly even when not running into the build_minus_one_cst case for _Fract types. We'd at least need to disable TYPE_SATURATING. I can change to just disable TYPE_SATURATING and !ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)) (there's no TYPE-based test for _Fract it seems?). Would you prefer that? Association could still affect rounding, and I don't think we document behavior of -fassociative-math on fixed-point? Richard. > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/torture/pr119532.c > > @@ -0,0 +1,14 @@ > > +/* { dg-do compile } */ > > +/* { dg-require-effective-target fixed_point } */ > > + > > +extern _Fract sinuhk_deg (unsigned short _Accum); > > + > > +_Fract cosuhk_deg (unsigned short _Accum deg) > > +{ > > + unsigned short _Accum _90_deg = 90uhk; > > + __asm ("" : "+r" (_90_deg)); > > + > > + return deg <= _90_deg > > + ? sinuhk_deg (_90_deg - deg) > > + : -sinuhk_deg (deg - _90_deg); > > +} > > diff --git a/gcc/tree-tailcall.cc b/gcc/tree-tailcall.cc > > index 8ba67522191..8ea1c8b5f99 100644 > > --- a/gcc/tree-tailcall.cc > > +++ b/gcc/tree-tailcall.cc > > @@ -361,6 +361,10 @@ process_assignment (gassign *stmt, > > if (FLOAT_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl)))) > > return FAIL; > > > > + /* We at least cannot build -1 for all fixed point types. */ > > + if (FIXED_POINT_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl)))) > > + return FAIL; > > + > > if (rhs_class == GIMPLE_UNARY_RHS > > && op0 == *ass_var) > > ; > > -- > > 2.43.0 > > Jakub > > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)