Hi Jakub,

Okay by me.  Thanks for fixing this!  Sorry I missed this bug on the list.
Feel free to CC me on any SLSR bugs.

-- Bill


> On Jan 4, 2018, at 3:23 PM, Jakub Jelinek <ja...@redhat.com> wrote:
> 
> Hi!
> 
> While the testcase could be perhaps handled with some extra effort (the
> issue there is just CSE of an early possibly throwing trapping addition,
> so maybe_cleanup_or_replace_eh_stmt + gimple_purge_dead_eh_edges +
> TODO_cleanup_cfg might do the job, but I'm afraid the pass wouldn't know
> what to do if it rewrites some arithmetics as a different one where
> EH edges would need to be added etc.
> 
> So, instead this patch just punts with -fnon-call-exceptions and possibly
> throwing statements.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> If later on we find something where it will be worthwhile to spend time on
> this, it can be easily reverted together with the full support for that.
> 
> 2018-01-04  Jakub Jelinek  <ja...@redhat.com>
> 
>       PR tree-optimization/83605
>       * gimple-ssa-strength-reduction.c: Include tree-eh.h.
>       (find_candidates_dom_walker::before_dom_children): Ignore stmts that
>       can throw.
> 
>       * gcc.dg/pr83605.c: New test.
> 
> --- gcc/gimple-ssa-strength-reduction.c.jj    2018-01-03 10:19:54.000000000 
> +0100
> +++ gcc/gimple-ssa-strength-reduction.c       2018-01-04 10:39:48.273512779 
> +0100
> @@ -55,6 +55,7 @@ along with GCC; see the file COPYING3.
> #include "params.h"
> #include "tree-ssa-address.h"
> #include "tree-affine.h"
> +#include "tree-eh.h"
> #include "builtins.h"
> 
> /* Information about a strength reduction candidate.  Each statement
> @@ -1747,6 +1748,9 @@ find_candidates_dom_walker::before_dom_c
>     {
>       gimple *gs = gsi_stmt (gsi);
> 
> +      if (stmt_could_throw_p (gs))
> +     continue;
> +
>       if (gimple_vuse (gs) && gimple_assign_single_p (gs))
>       slsr_process_ref (gs);
> 
> --- gcc/testsuite/gcc.dg/pr83605.c.jj 2018-01-04 10:35:20.874481057 +0100
> +++ gcc/testsuite/gcc.dg/pr83605.c    2018-01-04 10:35:01.972479109 +0100
> @@ -0,0 +1,20 @@
> +/* PR tree-optimization/83605 */
> +/* { dg-do compile } */
> +/* { dg-options "-O1 -ftrapv -fexceptions -fnon-call-exceptions" } */
> +
> +int a;
> +
> +int
> +foo (int x)
> +{
> +  int b = a;
> +  {
> +    int c;
> +    int *d = (x == 0) ? &c : &b;
> +
> +    for (a = 0; a < 2; ++a)
> +      c = (x + b) < a;
> +
> +    return *d;
> +  }
> +}
> 
>       Jakub
> 

Reply via email to