public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Add range/nonzero info to generated ADD_OVERFLOW and simplify
@ 2021-08-14  1:22 apinski
  2021-08-14  9:16 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: apinski @ 2021-08-14  1:22 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

From: Andrew Pinski <apinski@marvell.com>

Even though this does not change the generated code,
it does improve the initial RTL generation.

gcc/ChangeLog:

	* tree-ssa-math-opts.c (match_arith_overflow):
	Add range and nonzero bits information to
	the new overflow ssa name.  Also fold
	the use statement.
---
 gcc/tree-ssa-math-opts.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index c4a6492b50d..bb7edeaa6f7 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -4221,6 +4221,8 @@ match_arith_overflow (gimple_stmt_iterator *gsi, gimple *stmt,
 	}
     }
   tree ovf = make_ssa_name (type);
+  set_range_info (ovf, VR_RANGE, wi::zero (TYPE_PRECISION (type)), wi::one (TYPE_PRECISION (type)));
+  set_nonzero_bits (ovf, wi::one (TYPE_PRECISION (type)));
   g2 = gimple_build_assign (ovf, IMAGPART_EXPR,
 			    build1 (IMAGPART_EXPR, type, ctmp));
   if (code != BIT_NOT_EXPR)
@@ -4279,6 +4281,8 @@ match_arith_overflow (gimple_stmt_iterator *gsi, gimple *stmt,
 	      gimple_assign_set_rhs1 (use_stmt, cond);
 	    }
 	}
+      gimple_stmt_iterator gsi1 = gsi_for_stmt (use_stmt);
+      fold_stmt (&gsi1);
       update_stmt (use_stmt);
       if (code == MULT_EXPR && use_stmt != orig_use_stmt)
 	{
-- 
2.27.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Add range/nonzero info to generated ADD_OVERFLOW and simplify
  2021-08-14  1:22 [PATCH] Add range/nonzero info to generated ADD_OVERFLOW and simplify apinski
@ 2021-08-14  9:16 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2021-08-14  9:16 UTC (permalink / raw)
  To: apinski; +Cc: gcc-patches

On Fri, Aug 13, 2021 at 06:22:48PM -0700, apinski--- via Gcc-patches wrote:
> From: Andrew Pinski <apinski@marvell.com>
> 
> Even though this does not change the generated code,
> it does improve the initial RTL generation.
> 
> gcc/ChangeLog:
> 
> 	* tree-ssa-math-opts.c (match_arith_overflow):
> 	Add range and nonzero bits information to
> 	the new overflow ssa name.  Also fold
> 	the use statement.
> ---
>  gcc/tree-ssa-math-opts.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
> index c4a6492b50d..bb7edeaa6f7 100644
> --- a/gcc/tree-ssa-math-opts.c
> +++ b/gcc/tree-ssa-math-opts.c
> @@ -4221,6 +4221,8 @@ match_arith_overflow (gimple_stmt_iterator *gsi, gimple *stmt,
>  	}
>      }
>    tree ovf = make_ssa_name (type);
> +  set_range_info (ovf, VR_RANGE, wi::zero (TYPE_PRECISION (type)), wi::one (TYPE_PRECISION (type)));

Too long line.

> +  set_nonzero_bits (ovf, wi::one (TYPE_PRECISION (type)));

Are you sure this is really needed?
set_range_info should have computed that one from the range already:
  /* If it is a range, try to improve nonzero_bits from the min/max.  */
  if (range_type == VR_RANGE)
    {
      wide_int xorv = ri->get_min () ^ ri->get_max ();
      if (xorv != 0)
        xorv = wi::mask (precision - wi::clz (xorv), false, precision);
      ri->set_nonzero_bits (ri->get_nonzero_bits () & (ri->get_min () | xorv));
    }

> @@ -4279,6 +4281,8 @@ match_arith_overflow (gimple_stmt_iterator *gsi, gimple *stmt,
>  	      gimple_assign_set_rhs1 (use_stmt, cond);
>  	    }
>  	}
> +      gimple_stmt_iterator gsi1 = gsi_for_stmt (use_stmt);
> +      fold_stmt (&gsi1);
>        update_stmt (use_stmt);

I don't think it is safe to do that here.
First of all, the update_stmt is right after it, then some further code
that still uses use_stmt right below and this is in a loop that iterates imm
uses of that use_stmt too.
If you want to fold use_stmt, can't it be done after the whole loop?

>        if (code == MULT_EXPR && use_stmt != orig_use_stmt)
>  	{
> -- 
> 2.27.0

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-14  9:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-14  1:22 [PATCH] Add range/nonzero info to generated ADD_OVERFLOW and simplify apinski
2021-08-14  9:16 ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).