public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] Make some functions in CCP static.
@ 2023-07-25 19:07 Aldy Hernandez
  2023-07-25 19:07 ` [PATCH] Initialize value in bit_value_unop Aldy Hernandez
  0 siblings, 1 reply; 3+ messages in thread
From: Aldy Hernandez @ 2023-07-25 19:07 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

Committed as obvious.

gcc/ChangeLog:

	* tree-ssa-ccp.cc (value_mask_to_min_max): Make static.
	(bit_value_mult_const): Same.
	(get_individual_bits): Same.
---
 gcc/tree-ssa-ccp.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc
index 64d5fa81334..73fb7c11c64 100644
--- a/gcc/tree-ssa-ccp.cc
+++ b/gcc/tree-ssa-ccp.cc
@@ -1297,7 +1297,7 @@ ccp_fold (gimple *stmt)
    represented by the mask pair VAL and MASK with signedness SGN and
    precision PRECISION.  */
 
-void
+static void
 value_mask_to_min_max (widest_int *min, widest_int *max,
 		       const widest_int &val, const widest_int &mask,
 		       signop sgn, int precision)
@@ -1391,7 +1391,7 @@ bit_value_unop (enum tree_code code, signop type_sgn, int type_precision,
 
 /* Determine the mask pair *VAL and *MASK from multiplying the
    argument mask pair RVAL, RMASK by the unsigned constant C.  */
-void
+static void
 bit_value_mult_const (signop sgn, int width,
 		      widest_int *val, widest_int *mask,
 		      const widest_int &rval, const widest_int &rmask,
@@ -1453,7 +1453,7 @@ bit_value_mult_const (signop sgn, int width,
    bits in X (capped at the maximum value MAX).  For example, an X
    value 11, places 1, 2 and 8 in BITS and returns the value 3.  */
 
-unsigned int
+static unsigned int
 get_individual_bits (widest_int *bits, widest_int x, unsigned int max)
 {
   unsigned int count = 0;
-- 
2.41.0


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

* [PATCH] Initialize value in bit_value_unop.
  2023-07-25 19:07 [COMMITTED] Make some functions in CCP static Aldy Hernandez
@ 2023-07-25 19:07 ` Aldy Hernandez
  2023-07-26  8:19   ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Aldy Hernandez @ 2023-07-25 19:07 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

bit_value_binop initializes VAL regardless of the final mask.  It even
has a comment to that effect:

  /* Ensure that VAL is initialized (to any value).  */

However, bit_value_unop, which in theory shares the same API, does not.
This causes range-ops to choke on uninitialized VALs for some inputs to
ABS.

Instead of fixing the callers, it's cleaner to make bit_value_unop and
bit_value_binop consistent.

OK for trunk?

gcc/ChangeLog:

	* tree-ssa-ccp.cc (bit_value_unop): Initialize val when appropriate.
---
 gcc/tree-ssa-ccp.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc
index 73fb7c11c64..15e65f16008 100644
--- a/gcc/tree-ssa-ccp.cc
+++ b/gcc/tree-ssa-ccp.cc
@@ -1359,7 +1359,10 @@ bit_value_unop (enum tree_code code, signop type_sgn, int type_precision,
     case ABS_EXPR:
     case ABSU_EXPR:
       if (wi::sext (rmask, rtype_precision) == -1)
-	*mask = -1;
+	{
+	  *mask = -1;
+	  *val = 0;
+	}
       else if (wi::neg_p (rmask))
 	{
 	  /* Result is either rval or -rval.  */
@@ -1385,6 +1388,7 @@ bit_value_unop (enum tree_code code, signop type_sgn, int type_precision,
 
     default:
       *mask = -1;
+      *val = 0;
       break;
     }
 }
-- 
2.41.0


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

* Re: [PATCH] Initialize value in bit_value_unop.
  2023-07-25 19:07 ` [PATCH] Initialize value in bit_value_unop Aldy Hernandez
@ 2023-07-26  8:19   ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2023-07-26  8:19 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: GCC patches, Andrew MacLeod

On Tue, Jul 25, 2023 at 9:08 PM Aldy Hernandez via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> bit_value_binop initializes VAL regardless of the final mask.  It even
> has a comment to that effect:
>
>   /* Ensure that VAL is initialized (to any value).  */
>
> However, bit_value_unop, which in theory shares the same API, does not.
> This causes range-ops to choke on uninitialized VALs for some inputs to
> ABS.
>
> Instead of fixing the callers, it's cleaner to make bit_value_unop and
> bit_value_binop consistent.
>
> OK for trunk?

OK

> gcc/ChangeLog:
>
>         * tree-ssa-ccp.cc (bit_value_unop): Initialize val when appropriate.
> ---
>  gcc/tree-ssa-ccp.cc | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc
> index 73fb7c11c64..15e65f16008 100644
> --- a/gcc/tree-ssa-ccp.cc
> +++ b/gcc/tree-ssa-ccp.cc
> @@ -1359,7 +1359,10 @@ bit_value_unop (enum tree_code code, signop type_sgn, int type_precision,
>      case ABS_EXPR:
>      case ABSU_EXPR:
>        if (wi::sext (rmask, rtype_precision) == -1)
> -       *mask = -1;
> +       {
> +         *mask = -1;
> +         *val = 0;
> +       }
>        else if (wi::neg_p (rmask))
>         {
>           /* Result is either rval or -rval.  */
> @@ -1385,6 +1388,7 @@ bit_value_unop (enum tree_code code, signop type_sgn, int type_precision,
>
>      default:
>        *mask = -1;
> +      *val = 0;
>        break;
>      }
>  }
> --
> 2.41.0
>

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

end of thread, other threads:[~2023-07-26  8:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-25 19:07 [COMMITTED] Make some functions in CCP static Aldy Hernandez
2023-07-25 19:07 ` [PATCH] Initialize value in bit_value_unop Aldy Hernandez
2023-07-26  8:19   ` Richard Biener

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).