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?
> --- /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