On Tue, 24 Mar 2020, Jakub Jelinek wrote:

> On Tue, Mar 24, 2020 at 10:59:19AM +0100, Richard Biener wrote:
> > Likely
> > 
> >   /* Delete dead statements.  */
> >   gsi = gsi_start_bb (bb);
> >   while (!gsi_end_p (gsi))
> >     {
> > 
> > needs to instead work back-to-front for debug stmt adjustment to work
> 
> Indeed, that seems to work.  Ok for trunk if it passes bootstrap/regtest?

OK.

> 2020-03-24  Richard Biener  <rguent...@suse.de>
>           Jakub Jelinek  <ja...@redhat.com>
> 
>       PR debug/94283
>       * tree-if-conv.c (ifcvt_local_dce): Delete dead statements backwards.
> 
>       * gcc.dg/pr94283.c: New test.
> 
> --- gcc/tree-if-conv.c.jj     2020-03-24 09:34:35.152087914 +0100
> +++ gcc/tree-if-conv.c        2020-03-24 11:13:41.179903247 +0100
> @@ -2973,9 +2973,11 @@ ifcvt_local_dce (class loop *loop)
>       }
>      }
>    /* Delete dead statements.  */
> -  gsi = gsi_start_bb (bb);
> +  gsi = gsi_last_bb (bb);
>    while (!gsi_end_p (gsi))
>      {
> +      gimple_stmt_iterator gsiprev = gsi;
> +      gsi_prev (&gsiprev);
>        stmt = gsi_stmt (gsi);
>        if (gimple_store_p (stmt))
>       {
> @@ -2986,14 +2988,13 @@ ifcvt_local_dce (class loop *loop)
>         if (dse_classify_store (&write, stmt, false, NULL, NULL, latch_vdef)
>             == DSE_STORE_DEAD)
>           delete_dead_or_redundant_assignment (&gsi, "dead");
> -       else
> -         gsi_next (&gsi);
> +       gsi = gsiprev;
>         continue;
>       }
>  
>        if (gimple_plf (stmt, GF_PLF_2))
>       {
> -       gsi_next (&gsi);
> +       gsi = gsiprev;
>         continue;
>       }
>        if (dump_file && (dump_flags & TDF_DETAILS))
> @@ -3003,6 +3004,7 @@ ifcvt_local_dce (class loop *loop)
>       }
>        gsi_remove (&gsi, true);
>        release_defs (stmt);
> +      gsi = gsiprev;
>      }
>  }
>  
> --- gcc/testsuite/gcc.dg/pr94283.c.jj 2020-03-24 11:15:35.782163250 +0100
> +++ gcc/testsuite/gcc.dg/pr94283.c    2020-03-24 11:16:37.909219978 +0100
> @@ -0,0 +1,16 @@
> +/* PR debug/94283 */
> +/* { dg-do compile } */
> +/* { dg-options "-O3 -fno-tree-dce -fcompare-debug" } */
> +
> +void
> +foo (int *n)
> +{
> +  for (int i = 0; i < 32; i++)
> +    {
> +      int x = 0;
> +      x++;
> +      if (i & 4)
> +     x++;
> +      x++;
> +    }
> +}
> 
> 
>       Jakub
> 
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

Reply via email to