public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Read global value/mask in IPA.
@ 2023-07-17 13:14 Aldy Hernandez
  2023-07-18 17:37 ` Aldy Hernandez
  2023-07-25  6:32 ` Aldy Hernandez
  0 siblings, 2 replies; 6+ messages in thread
From: Aldy Hernandez @ 2023-07-17 13:14 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Martin Jambor, Aldy Hernandez

Instead of reading the known zero bits in IPA, read the value/mask
pair which is available.

There is a slight change of behavior here.  I have removed the check
for SSA_NAME, as the ranger can calculate the range and value/mask for
INTEGER_CST.  This simplifies the code a bit, since there's no special
casing when setting the jfunc bits.  The default range for VR is
undefined, so I think it's safe just to check for undefined_p().

OK?

gcc/ChangeLog:

	* ipa-prop.cc (ipa_compute_jump_functions_for_edge): Read global
	value/mask.
---
 gcc/ipa-prop.cc | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 5d790ff1265..4f6ed7b89bd 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -2402,8 +2402,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
 	}
       else
 	{
-	  if (TREE_CODE (arg) == SSA_NAME
-	      && param_type
+	  if (param_type
 	      && Value_Range::supports_type_p (TREE_TYPE (arg))
 	      && Value_Range::supports_type_p (param_type)
 	      && irange::supports_p (TREE_TYPE (arg))
@@ -2422,15 +2421,14 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
 	    gcc_assert (!jfunc->m_vr);
 	}
 
-      if (INTEGRAL_TYPE_P (TREE_TYPE (arg))
-	  && (TREE_CODE (arg) == SSA_NAME || TREE_CODE (arg) == INTEGER_CST))
+      if (INTEGRAL_TYPE_P (TREE_TYPE (arg)) && !vr.undefined_p ())
 	{
-	  if (TREE_CODE (arg) == SSA_NAME)
-	    ipa_set_jfunc_bits (jfunc, 0,
-				widest_int::from (get_nonzero_bits (arg),
-						  TYPE_SIGN (TREE_TYPE (arg))));
-	  else
-	    ipa_set_jfunc_bits (jfunc, wi::to_widest (arg), 0);
+	  irange &r = as_a <irange> (vr);
+	  irange_bitmask bm = r.get_bitmask ();
+	  signop sign = TYPE_SIGN (TREE_TYPE (arg));
+	  ipa_set_jfunc_bits (jfunc,
+			      widest_int::from (bm.value (), sign),
+			      widest_int::from (bm.mask (), sign));
 	}
       else if (POINTER_TYPE_P (TREE_TYPE (arg)))
 	{
-- 
2.40.1


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

* Re: [PATCH] Read global value/mask in IPA.
  2023-07-17 13:14 [PATCH] Read global value/mask in IPA Aldy Hernandez
@ 2023-07-18 17:37 ` Aldy Hernandez
  2023-07-31 16:47   ` Martin Jambor
  2023-07-25  6:32 ` Aldy Hernandez
  1 sibling, 1 reply; 6+ messages in thread
From: Aldy Hernandez @ 2023-07-18 17:37 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Martin Jambor

[-- Attachment #1: Type: text/plain, Size: 1068 bytes --]



On 7/17/23 15:14, Aldy Hernandez wrote:
> Instead of reading the known zero bits in IPA, read the value/mask
> pair which is available.
> 
> There is a slight change of behavior here.  I have removed the check
> for SSA_NAME, as the ranger can calculate the range and value/mask for
> INTEGER_CST.  This simplifies the code a bit, since there's no special
> casing when setting the jfunc bits.  The default range for VR is
> undefined, so I think it's safe just to check for undefined_p().

Final round of tests revealed a regression for which I've adjusted the 
testcase.

It turns out g++.dg/ipa/pure-const-3.C fails because IPA can now pick up 
value/mask from any pass that has an integrated ranger.  The test was 
previously disabling evrp and CCP, but now VRP[12], jump threading, and 
DOM can make value/mask adjustments visible to IPA so they must be 
disabled as well.

We've run into these scenarios multiple times in the past-- any 
improvements to the ranger pipeline causes everyone to get smarter, 
making changes visible earlier in the pipeline.

Aldy

[-- Attachment #2: 0001-Read-global-value-mask-in-IPA.patch --]
[-- Type: text/x-patch, Size: 2982 bytes --]

From e1dfd4d6b3d3bf09d55b6ea3ac732462c7030802 Mon Sep 17 00:00:00 2001
From: Aldy Hernandez <aldyh@redhat.com>
Date: Fri, 14 Jul 2023 12:38:16 +0200
Subject: [PATCH] Read global value/mask in IPA.

Instead of reading the known zero bits in IPA, read the value/mask
pair which is available.

There is a slight change of behavior here.  I have removed the check
for SSA_NAME, as the ranger can calculate the range and value/mask for
INTEGER_CST.  This simplifies the code a bit, since there's no special
casing when setting the jfunc bits.  The default range for VR is
undefined, so I think it's safe just to check for undefined_p().

gcc/ChangeLog:

	* ipa-prop.cc (ipa_compute_jump_functions_for_edge): Read global
	value/mask.

gcc/testsuite/ChangeLog:

	* g++.dg/ipa/pure-const-3.C: Adjust for smarter value/mask being
	read by ranger earlier than expected by test.
---
 gcc/ipa-prop.cc                         | 18 ++++++++----------
 gcc/testsuite/g++.dg/ipa/pure-const-3.C |  2 +-
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 5d790ff1265..4f6ed7b89bd 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -2402,8 +2402,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
 	}
       else
 	{
-	  if (TREE_CODE (arg) == SSA_NAME
-	      && param_type
+	  if (param_type
 	      && Value_Range::supports_type_p (TREE_TYPE (arg))
 	      && Value_Range::supports_type_p (param_type)
 	      && irange::supports_p (TREE_TYPE (arg))
@@ -2422,15 +2421,14 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
 	    gcc_assert (!jfunc->m_vr);
 	}
 
-      if (INTEGRAL_TYPE_P (TREE_TYPE (arg))
-	  && (TREE_CODE (arg) == SSA_NAME || TREE_CODE (arg) == INTEGER_CST))
+      if (INTEGRAL_TYPE_P (TREE_TYPE (arg)) && !vr.undefined_p ())
 	{
-	  if (TREE_CODE (arg) == SSA_NAME)
-	    ipa_set_jfunc_bits (jfunc, 0,
-				widest_int::from (get_nonzero_bits (arg),
-						  TYPE_SIGN (TREE_TYPE (arg))));
-	  else
-	    ipa_set_jfunc_bits (jfunc, wi::to_widest (arg), 0);
+	  irange &r = as_a <irange> (vr);
+	  irange_bitmask bm = r.get_bitmask ();
+	  signop sign = TYPE_SIGN (TREE_TYPE (arg));
+	  ipa_set_jfunc_bits (jfunc,
+			      widest_int::from (bm.value (), sign),
+			      widest_int::from (bm.mask (), sign));
 	}
       else if (POINTER_TYPE_P (TREE_TYPE (arg)))
 	{
diff --git a/gcc/testsuite/g++.dg/ipa/pure-const-3.C b/gcc/testsuite/g++.dg/ipa/pure-const-3.C
index b4a4673e86e..e43cf09af27 100644
--- a/gcc/testsuite/g++.dg/ipa/pure-const-3.C
+++ b/gcc/testsuite/g++.dg/ipa/pure-const-3.C
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-ipa-vrp -fdump-tree-optimized -fno-tree-ccp -fdisable-tree-evrp"  } */
+/* { dg-options "-O2 -fno-ipa-vrp -fdump-tree-optimized -fno-tree-ccp -fdisable-tree-evrp -fdisable-tree-vrp1 -fdisable-tree-vrp2 -fno-thread-jumps -fno-tree-dominator-opts"  } */
 int *ptr;
 static int barvar;
 static int b(int a);
-- 
2.40.1


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

* Re: [PATCH] Read global value/mask in IPA.
  2023-07-17 13:14 [PATCH] Read global value/mask in IPA Aldy Hernandez
  2023-07-18 17:37 ` Aldy Hernandez
@ 2023-07-25  6:32 ` Aldy Hernandez
  2023-07-31 14:40   ` Aldy Hernandez
  1 sibling, 1 reply; 6+ messages in thread
From: Aldy Hernandez @ 2023-07-25  6:32 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Martin Jambor

[-- Attachment #1: Type: text/plain, Size: 2426 bytes --]

Ping

On Mon, Jul 17, 2023, 15:14 Aldy Hernandez <aldyh@redhat.com> wrote:

> Instead of reading the known zero bits in IPA, read the value/mask
> pair which is available.
>
> There is a slight change of behavior here.  I have removed the check
> for SSA_NAME, as the ranger can calculate the range and value/mask for
> INTEGER_CST.  This simplifies the code a bit, since there's no special
> casing when setting the jfunc bits.  The default range for VR is
> undefined, so I think it's safe just to check for undefined_p().
>
> OK?
>
> gcc/ChangeLog:
>
>         * ipa-prop.cc (ipa_compute_jump_functions_for_edge): Read global
>         value/mask.
> ---
>  gcc/ipa-prop.cc | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
> index 5d790ff1265..4f6ed7b89bd 100644
> --- a/gcc/ipa-prop.cc
> +++ b/gcc/ipa-prop.cc
> @@ -2402,8 +2402,7 @@ ipa_compute_jump_functions_for_edge (struct
> ipa_func_body_info *fbi,
>         }
>        else
>         {
> -         if (TREE_CODE (arg) == SSA_NAME
> -             && param_type
> +         if (param_type
>               && Value_Range::supports_type_p (TREE_TYPE (arg))
>               && Value_Range::supports_type_p (param_type)
>               && irange::supports_p (TREE_TYPE (arg))
> @@ -2422,15 +2421,14 @@ ipa_compute_jump_functions_for_edge (struct
> ipa_func_body_info *fbi,
>             gcc_assert (!jfunc->m_vr);
>         }
>
> -      if (INTEGRAL_TYPE_P (TREE_TYPE (arg))
> -         && (TREE_CODE (arg) == SSA_NAME || TREE_CODE (arg) ==
> INTEGER_CST))
> +      if (INTEGRAL_TYPE_P (TREE_TYPE (arg)) && !vr.undefined_p ())
>         {
> -         if (TREE_CODE (arg) == SSA_NAME)
> -           ipa_set_jfunc_bits (jfunc, 0,
> -                               widest_int::from (get_nonzero_bits (arg),
> -                                                 TYPE_SIGN (TREE_TYPE
> (arg))));
> -         else
> -           ipa_set_jfunc_bits (jfunc, wi::to_widest (arg), 0);
> +         irange &r = as_a <irange> (vr);
> +         irange_bitmask bm = r.get_bitmask ();
> +         signop sign = TYPE_SIGN (TREE_TYPE (arg));
> +         ipa_set_jfunc_bits (jfunc,
> +                             widest_int::from (bm.value (), sign),
> +                             widest_int::from (bm.mask (), sign));
>         }
>        else if (POINTER_TYPE_P (TREE_TYPE (arg)))
>         {
> --
> 2.40.1
>
>

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

* Re: [PATCH] Read global value/mask in IPA.
  2023-07-25  6:32 ` Aldy Hernandez
@ 2023-07-31 14:40   ` Aldy Hernandez
  0 siblings, 0 replies; 6+ messages in thread
From: Aldy Hernandez @ 2023-07-31 14:40 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Martin Jambor

PING * 2

On Tue, Jul 25, 2023 at 8:32 AM Aldy Hernandez <aldyh@redhat.com> wrote:
>
> Ping
>
> On Mon, Jul 17, 2023, 15:14 Aldy Hernandez <aldyh@redhat.com> wrote:
>>
>> Instead of reading the known zero bits in IPA, read the value/mask
>> pair which is available.
>>
>> There is a slight change of behavior here.  I have removed the check
>> for SSA_NAME, as the ranger can calculate the range and value/mask for
>> INTEGER_CST.  This simplifies the code a bit, since there's no special
>> casing when setting the jfunc bits.  The default range for VR is
>> undefined, so I think it's safe just to check for undefined_p().
>>
>> OK?
>>
>> gcc/ChangeLog:
>>
>>         * ipa-prop.cc (ipa_compute_jump_functions_for_edge): Read global
>>         value/mask.
>> ---
>>  gcc/ipa-prop.cc | 18 ++++++++----------
>>  1 file changed, 8 insertions(+), 10 deletions(-)
>>
>> diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
>> index 5d790ff1265..4f6ed7b89bd 100644
>> --- a/gcc/ipa-prop.cc
>> +++ b/gcc/ipa-prop.cc
>> @@ -2402,8 +2402,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
>>         }
>>        else
>>         {
>> -         if (TREE_CODE (arg) == SSA_NAME
>> -             && param_type
>> +         if (param_type
>>               && Value_Range::supports_type_p (TREE_TYPE (arg))
>>               && Value_Range::supports_type_p (param_type)
>>               && irange::supports_p (TREE_TYPE (arg))
>> @@ -2422,15 +2421,14 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
>>             gcc_assert (!jfunc->m_vr);
>>         }
>>
>> -      if (INTEGRAL_TYPE_P (TREE_TYPE (arg))
>> -         && (TREE_CODE (arg) == SSA_NAME || TREE_CODE (arg) == INTEGER_CST))
>> +      if (INTEGRAL_TYPE_P (TREE_TYPE (arg)) && !vr.undefined_p ())
>>         {
>> -         if (TREE_CODE (arg) == SSA_NAME)
>> -           ipa_set_jfunc_bits (jfunc, 0,
>> -                               widest_int::from (get_nonzero_bits (arg),
>> -                                                 TYPE_SIGN (TREE_TYPE (arg))));
>> -         else
>> -           ipa_set_jfunc_bits (jfunc, wi::to_widest (arg), 0);
>> +         irange &r = as_a <irange> (vr);
>> +         irange_bitmask bm = r.get_bitmask ();
>> +         signop sign = TYPE_SIGN (TREE_TYPE (arg));
>> +         ipa_set_jfunc_bits (jfunc,
>> +                             widest_int::from (bm.value (), sign),
>> +                             widest_int::from (bm.mask (), sign));
>>         }
>>        else if (POINTER_TYPE_P (TREE_TYPE (arg)))
>>         {
>> --
>> 2.40.1
>>


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

* Re: [PATCH] Read global value/mask in IPA.
  2023-07-18 17:37 ` Aldy Hernandez
@ 2023-07-31 16:47   ` Martin Jambor
  2023-08-03 18:21     ` Aldy Hernandez
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Jambor @ 2023-07-31 16:47 UTC (permalink / raw)
  To: Aldy Hernandez, GCC patches; +Cc: Andrew MacLeod

Hello,

On Tue, Jul 18 2023, Aldy Hernandez wrote:
> On 7/17/23 15:14, Aldy Hernandez wrote:
>> Instead of reading the known zero bits in IPA, read the value/mask
>> pair which is available.
>> 
>> There is a slight change of behavior here.  I have removed the check
>> for SSA_NAME, as the ranger can calculate the range and value/mask for
>> INTEGER_CST.  This simplifies the code a bit, since there's no special
>> casing when setting the jfunc bits.  The default range for VR is
>> undefined, so I think it's safe just to check for undefined_p().
>
> Final round of tests revealed a regression for which I've adjusted the 
> testcase.
>
> It turns out g++.dg/ipa/pure-const-3.C fails because IPA can now pick up 
> value/mask from any pass that has an integrated ranger.  The test was 
> previously disabling evrp and CCP, but now VRP[12], jump threading, and 
> DOM can make value/mask adjustments visible to IPA so they must be 
> disabled as well.

So can this be then converted into a new testcase that would test that
we can now derive something we could not in the past?

The patch is OK (but the testcase above is highly desirable).

Thanks for keeping looking at IPA-VR.

Martin


>
> We've run into these scenarios multiple times in the past-- any 
> improvements to the ranger pipeline causes everyone to get smarter, 
> making changes visible earlier in the pipeline.
>
> Aldy
> From e1dfd4d6b3d3bf09d55b6ea3ac732462c7030802 Mon Sep 17 00:00:00 2001
> From: Aldy Hernandez <aldyh@redhat.com>
> Date: Fri, 14 Jul 2023 12:38:16 +0200
> Subject: [PATCH] Read global value/mask in IPA.
>
> Instead of reading the known zero bits in IPA, read the value/mask
> pair which is available.
>
> There is a slight change of behavior here.  I have removed the check
> for SSA_NAME, as the ranger can calculate the range and value/mask for
> INTEGER_CST.  This simplifies the code a bit, since there's no special
> casing when setting the jfunc bits.  The default range for VR is
> undefined, so I think it's safe just to check for undefined_p().
>
> gcc/ChangeLog:
>
> 	* ipa-prop.cc (ipa_compute_jump_functions_for_edge): Read global
> 	value/mask.
>
> gcc/testsuite/ChangeLog:
>
> 	* g++.dg/ipa/pure-const-3.C: Adjust for smarter value/mask being
> 	read by ranger earlier than expected by test.
> ---
>  gcc/ipa-prop.cc                         | 18 ++++++++----------
>  gcc/testsuite/g++.dg/ipa/pure-const-3.C |  2 +-
>  2 files changed, 9 insertions(+), 11 deletions(-)
>
> diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
> index 5d790ff1265..4f6ed7b89bd 100644
> --- a/gcc/ipa-prop.cc
> +++ b/gcc/ipa-prop.cc
> @@ -2402,8 +2402,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
>  	}
>        else
>  	{
> -	  if (TREE_CODE (arg) == SSA_NAME
> -	      && param_type
> +	  if (param_type
>  	      && Value_Range::supports_type_p (TREE_TYPE (arg))
>  	      && Value_Range::supports_type_p (param_type)
>  	      && irange::supports_p (TREE_TYPE (arg))
> @@ -2422,15 +2421,14 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
>  	    gcc_assert (!jfunc->m_vr);
>  	}
>  
> -      if (INTEGRAL_TYPE_P (TREE_TYPE (arg))
> -	  && (TREE_CODE (arg) == SSA_NAME || TREE_CODE (arg) == INTEGER_CST))
> +      if (INTEGRAL_TYPE_P (TREE_TYPE (arg)) && !vr.undefined_p ())
>  	{
> -	  if (TREE_CODE (arg) == SSA_NAME)
> -	    ipa_set_jfunc_bits (jfunc, 0,
> -				widest_int::from (get_nonzero_bits (arg),
> -						  TYPE_SIGN (TREE_TYPE (arg))));
> -	  else
> -	    ipa_set_jfunc_bits (jfunc, wi::to_widest (arg), 0);
> +	  irange &r = as_a <irange> (vr);
> +	  irange_bitmask bm = r.get_bitmask ();
> +	  signop sign = TYPE_SIGN (TREE_TYPE (arg));
> +	  ipa_set_jfunc_bits (jfunc,
> +			      widest_int::from (bm.value (), sign),
> +			      widest_int::from (bm.mask (), sign));
>  	}
>        else if (POINTER_TYPE_P (TREE_TYPE (arg)))
>  	{
> diff --git a/gcc/testsuite/g++.dg/ipa/pure-const-3.C b/gcc/testsuite/g++.dg/ipa/pure-const-3.C
> index b4a4673e86e..e43cf09af27 100644
> --- a/gcc/testsuite/g++.dg/ipa/pure-const-3.C
> +++ b/gcc/testsuite/g++.dg/ipa/pure-const-3.C
> @@ -1,5 +1,5 @@
>  /* { dg-do compile } */
> -/* { dg-options "-O2 -fno-ipa-vrp -fdump-tree-optimized -fno-tree-ccp -fdisable-tree-evrp"  } */
> +/* { dg-options "-O2 -fno-ipa-vrp -fdump-tree-optimized -fno-tree-ccp -fdisable-tree-evrp -fdisable-tree-vrp1 -fdisable-tree-vrp2 -fno-thread-jumps -fno-tree-dominator-opts"  } */
>  int *ptr;
>  static int barvar;
>  static int b(int a);
> -- 
> 2.40.1

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

* Re: [PATCH] Read global value/mask in IPA.
  2023-07-31 16:47   ` Martin Jambor
@ 2023-08-03 18:21     ` Aldy Hernandez
  0 siblings, 0 replies; 6+ messages in thread
From: Aldy Hernandez @ 2023-08-03 18:21 UTC (permalink / raw)
  To: Martin Jambor, GCC patches; +Cc: Andrew MacLeod

[-- Attachment #1: Type: text/plain, Size: 1347 bytes --]



On 7/31/23 18:47, Martin Jambor wrote:
> Hello,
> 
> On Tue, Jul 18 2023, Aldy Hernandez wrote:
>> On 7/17/23 15:14, Aldy Hernandez wrote:
>>> Instead of reading the known zero bits in IPA, read the value/mask
>>> pair which is available.
>>>
>>> There is a slight change of behavior here.  I have removed the check
>>> for SSA_NAME, as the ranger can calculate the range and value/mask for
>>> INTEGER_CST.  This simplifies the code a bit, since there's no special
>>> casing when setting the jfunc bits.  The default range for VR is
>>> undefined, so I think it's safe just to check for undefined_p().
>>
>> Final round of tests revealed a regression for which I've adjusted the
>> testcase.
>>
>> It turns out g++.dg/ipa/pure-const-3.C fails because IPA can now pick up
>> value/mask from any pass that has an integrated ranger.  The test was
>> previously disabling evrp and CCP, but now VRP[12], jump threading, and
>> DOM can make value/mask adjustments visible to IPA so they must be
>> disabled as well.
> 
> So can this be then converted into a new testcase that would test that
> we can now derive something we could not in the past?

Good idea.

This is what I'm testing.  I'm basically testing for "Propagated bits" 
in the ipa-cp pass which is where we are able to propagate more things.

I will commit if it succeeds.

Thanks.
Aldy

[-- Attachment #2: 0001-Read-global-value-mask-in-IPA.patch --]
[-- Type: text/x-patch, Size: 4948 bytes --]

From 57fae00ccccc11070545dd0eacaa5c04547cc553 Mon Sep 17 00:00:00 2001
From: Aldy Hernandez <aldyh@redhat.com>
Date: Fri, 14 Jul 2023 12:38:16 +0200
Subject: [PATCH] Read global value/mask in IPA.

Instead of reading the known zero bits in IPA, read the value/mask
pair which is available.

There is a slight change of behavior here.  I have removed the check
for SSA_NAME, as the ranger can calculate the range and value/mask for
INTEGER_CST.  This simplifies the code a bit, since there's no special
casing when setting the jfunc bits.  The default range for VR is
undefined, so I think it's safe just to check for undefined_p().

gcc/ChangeLog:

	* ipa-prop.cc (ipa_compute_jump_functions_for_edge): Read global
	value/mask.

gcc/testsuite/ChangeLog:

	* g++.dg/ipa/pure-const-3.C: Move source to...
	* g++.dg/ipa/pure-const-3.h: ...here, and adjust original test
	accordingly.
	* g++.dg/ipa/pure-const-3b.C: New.
---
 gcc/ipa-prop.cc                          | 18 ++++++-------
 gcc/testsuite/g++.dg/ipa/pure-const-3.C  | 34 +++---------------------
 gcc/testsuite/g++.dg/ipa/pure-const-3.h  | 29 ++++++++++++++++++++
 gcc/testsuite/g++.dg/ipa/pure-const-3b.C |  6 +++++
 4 files changed, 47 insertions(+), 40 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pure-const-3.h
 create mode 100644 gcc/testsuite/g++.dg/ipa/pure-const-3b.C

diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 5d790ff1265..4f6ed7b89bd 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -2402,8 +2402,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
 	}
       else
 	{
-	  if (TREE_CODE (arg) == SSA_NAME
-	      && param_type
+	  if (param_type
 	      && Value_Range::supports_type_p (TREE_TYPE (arg))
 	      && Value_Range::supports_type_p (param_type)
 	      && irange::supports_p (TREE_TYPE (arg))
@@ -2422,15 +2421,14 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
 	    gcc_assert (!jfunc->m_vr);
 	}
 
-      if (INTEGRAL_TYPE_P (TREE_TYPE (arg))
-	  && (TREE_CODE (arg) == SSA_NAME || TREE_CODE (arg) == INTEGER_CST))
+      if (INTEGRAL_TYPE_P (TREE_TYPE (arg)) && !vr.undefined_p ())
 	{
-	  if (TREE_CODE (arg) == SSA_NAME)
-	    ipa_set_jfunc_bits (jfunc, 0,
-				widest_int::from (get_nonzero_bits (arg),
-						  TYPE_SIGN (TREE_TYPE (arg))));
-	  else
-	    ipa_set_jfunc_bits (jfunc, wi::to_widest (arg), 0);
+	  irange &r = as_a <irange> (vr);
+	  irange_bitmask bm = r.get_bitmask ();
+	  signop sign = TYPE_SIGN (TREE_TYPE (arg));
+	  ipa_set_jfunc_bits (jfunc,
+			      widest_int::from (bm.value (), sign),
+			      widest_int::from (bm.mask (), sign));
 	}
       else if (POINTER_TYPE_P (TREE_TYPE (arg)))
 	{
diff --git a/gcc/testsuite/g++.dg/ipa/pure-const-3.C b/gcc/testsuite/g++.dg/ipa/pure-const-3.C
index b4a4673e86e..62d355b4ce7 100644
--- a/gcc/testsuite/g++.dg/ipa/pure-const-3.C
+++ b/gcc/testsuite/g++.dg/ipa/pure-const-3.C
@@ -1,32 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-ipa-vrp -fdump-tree-optimized -fno-tree-ccp -fdisable-tree-evrp"  } */
-int *ptr;
-static int barvar;
-static int b(int a);
-/* We can not detect A to be const because it may be interposed by unoptimized
-   body.  */
-inline
-__attribute__ ((noinline))
-int a(int a)
-{
-  if (a>0)
-    return b(a-1);
-  return *ptr == *ptr;
-}
-inline
-__attribute__ ((noinline))
-static int b(int p)
-{
-  if (p<0)
-    return a(p+1);
-  return 1;
-}
-int main()
-{
-  int aa;
-  ptr = &barvar;
-  aa=!b(3);
-  ptr = 0;
-  return aa;
-}
+/* { dg-options "-O2 -fno-ipa-vrp -fdump-tree-optimized -fno-tree-ccp -fdisable-tree-evrp -fdisable-tree-vrp1 -fdisable-tree-vrp2 -fno-thread-jumps -fno-tree-dominator-opts"  } */
+
+#include "pure-const-3.h"
+
 /* { dg-final { scan-tree-dump "barvar"  "optimized"  } } */
diff --git a/gcc/testsuite/g++.dg/ipa/pure-const-3.h b/gcc/testsuite/g++.dg/ipa/pure-const-3.h
new file mode 100644
index 00000000000..61d162f541e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pure-const-3.h
@@ -0,0 +1,29 @@
+int *ptr;
+static int barvar;
+static int b(int a);
+/* We can not detect A to be const because it may be interposed by unoptimized
+   body.  */
+inline
+__attribute__ ((noinline))
+int a(int a)
+{
+  if (a>0)
+    return b(a-1);
+  return *ptr == *ptr;
+}
+inline
+__attribute__ ((noinline))
+static int b(int p)
+{
+  if (p<0)
+    return a(p+1);
+  return 1;
+}
+int main()
+{
+  int aa;
+  ptr = &barvar;
+  aa=!b(3);
+  ptr = 0;
+  return aa;
+}
diff --git a/gcc/testsuite/g++.dg/ipa/pure-const-3b.C b/gcc/testsuite/g++.dg/ipa/pure-const-3b.C
new file mode 100644
index 00000000000..eaa48429b4e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pure-const-3b.C
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-ipa-vrp -fno-tree-ccp -fdisable-tree-evrp -fno-thread-jumps -fdump-ipa-cp-details" } */
+
+#include "pure-const-3.h"
+
+/* { dg-final { scan-ipa-dump "Propagated bits info for function int b"  "cp"  } } */
-- 
2.41.0


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

end of thread, other threads:[~2023-08-03 18:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-17 13:14 [PATCH] Read global value/mask in IPA Aldy Hernandez
2023-07-18 17:37 ` Aldy Hernandez
2023-07-31 16:47   ` Martin Jambor
2023-08-03 18:21     ` Aldy Hernandez
2023-07-25  6:32 ` Aldy Hernandez
2023-07-31 14:40   ` Aldy Hernandez

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