On Mon, Jun 16, 2025, 10:57 PM Jakub Jelinek <ja...@redhat.com> wrote:

> Hi!
>
> The following testcase ICEs, because optimize_crc_loop inserts a call
> statement before labels instead of after labels.
>
> Fixed thusly (plus fixed other issues noticed around it),
> bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/15.2?
>

LGTM but I can't approve it.

Thanks,
Andrew



> 2025-06-17  Jakub Jelinek  <ja...@redhat.com>
>
>         PR tree-optimization/120677
>         * gimple-crc-optimization.cc (crc_optimization::optimize_crc_loop):
>         Insert before gsi_after_labels instead of gsi_start_bb.  Use
>         gimple_bb (output_crc) instead of output_crc->bb.  Formatting fix.
>
>         * gcc.c-torture/execute/pr120677.c: New test.
>
> --- gcc/gimple-crc-optimization.cc.jj   2025-04-08 14:08:51.619276743 +0200
> +++ gcc/gimple-crc-optimization.cc      2025-06-16 21:52:55.864229216 +0200
> @@ -1261,15 +1261,12 @@ crc_optimization::optimize_crc_loop (gph
>    loc = EXPR_LOCATION (phi_result);
>
>    /* Add IFN call and write the return value in the phi_result.  */
> -  gcall *call
> -      = gimple_build_call_internal (ifn, 3,
> -                                   m_crc_arg,
> -                                   m_data_arg,
> -                                   polynomial_arg);
> +  gcall *call = gimple_build_call_internal (ifn, 3, m_crc_arg, m_data_arg,
> +                                           polynomial_arg);
>
>    gimple_call_set_lhs (call, phi_result);
>    gimple_set_location (call, loc);
> -  gimple_stmt_iterator si = gsi_start_bb (output_crc->bb);
> +  gimple_stmt_iterator si = gsi_after_labels (gimple_bb (output_crc));
>    gsi_insert_before (&si, call, GSI_SAME_STMT);
>
>    /* Remove phi statement, which was holding CRC result.  */
> --- gcc/testsuite/gcc.c-torture/execute/pr120677.c.jj   2025-06-16
> 21:58:57.149514696 +0200
> +++ gcc/testsuite/gcc.c-torture/execute/pr120677.c      2025-06-16
> 21:58:29.438876302 +0200
> @@ -0,0 +1,31 @@
> +/* PR tree-optimization/120677 */
> +/* { dg-do run { target int32plus } } */
> +
> +unsigned a;
> +int b, e;
> +
> +int
> +foo (int d)
> +{
> +  switch (d)
> +    {
> +    case 0:
> +    case 2:
> +      return 0;
> +    default:
> +      return 1;
> +    }
> +}
> +
> +int
> +main ()
> +{
> +  for (b = 8; b; b--)
> +    if (a & 1)
> +      a = a >> 1 ^ 20000000;
> +    else
> +      a >>= 1;
> +  e = foo (0);
> +  if (e || a)
> +    __builtin_abort ();
> +}
>
>         Jakub
>
>

Reply via email to