diff mbox series

tree-optimization/83072 - Allow more precision when querying from fold_const.

Message ID 159ff48e-32cf-da90-5b74-262b94d04095@redhat.com
State New
Headers show
Series tree-optimization/83072 - Allow more precision when querying from fold_const. | expand

Commit Message

Andrew MacLeod Jan. 13, 2022, 1:57 p.m. UTC
This patch actually addresses a few PRs.

The root PR was 97909.   Ranger context functionality was added to 
fold_const back in early November 
(https://gcc.gnu.org/pipermail/gcc-patches/2021-November/583216.html)

The other 2 PRs mentioned (83072 and 83073) partially worked after this, 
but the original patch did not change the result of the query in 
expr_not_equal_to () to a multi-range object.

This patch simply changes the value_range variable in that routine to an 
int_range<5> so we can pick up more precision. This in turn allows us to 
capture all the tests as expected.

Bootstrapped on x86_64-pc-linux-gnu with no regressions.

OK for trunk?

Andrew

Comments

Richard Biener Jan. 13, 2022, 3:13 p.m. UTC | #1
On Thu, Jan 13, 2022 at 2:59 PM Andrew MacLeod via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> This patch actually addresses a few PRs.
>
> The root PR was 97909.   Ranger context functionality was added to
> fold_const back in early November
> (https://gcc.gnu.org/pipermail/gcc-patches/2021-November/583216.html)
>
> The other 2 PRs mentioned (83072 and 83073) partially worked after this,
> but the original patch did not change the result of the query in
> expr_not_equal_to () to a multi-range object.
>
> This patch simply changes the value_range variable in that routine to an
> int_range<5> so we can pick up more precision. This in turn allows us to
> capture all the tests as expected.
>
> Bootstrapped on x86_64-pc-linux-gnu with no regressions.
>
> OK for trunk?

OK (though I wonder why not use int_range_max?)

Thanks,
Richard.

>
> Andrew
Andrew MacLeod Jan. 13, 2022, 4:58 p.m. UTC | #2
On 1/13/22 10:13, Richard Biener wrote:
> On Thu, Jan 13, 2022 at 2:59 PM Andrew MacLeod via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
>> This patch actually addresses a few PRs.
>>
>> The root PR was 97909.   Ranger context functionality was added to
>> fold_const back in early November
>> (https://gcc.gnu.org/pipermail/gcc-patches/2021-November/583216.html)
>>
>> The other 2 PRs mentioned (83072 and 83073) partially worked after this,
>> but the original patch did not change the result of the query in
>> expr_not_equal_to () to a multi-range object.
>>
>> This patch simply changes the value_range variable in that routine to an
>> int_range<5> so we can pick up more precision. This in turn allows us to
>> capture all the tests as expected.
>>
>> Bootstrapped on x86_64-pc-linux-gnu with no regressions.
>>
>> OK for trunk?
> OK (though I wonder why not use int_range_max?)
>
No good reason..  Initially it was just because I wasn't familiar with 
what call chains might end up here, but really, I guess it doesn't matter.

I can change it to int_range_max before committing it.

Andrew
diff mbox series

Patch

From 329626a426d21dfe484053f7b6ac4f2d0c14fa0e Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Wed, 12 Jan 2022 13:31:08 -0500
Subject: [PATCH 2/2] Allow more precision when querying from fold_const.

fold_const::expr_not_equal_to queries for a current range, but still uses
the old value_range class.  This is causing it to miss opportunities when
ranger can provide something better.

	PR tree-optimization/83072
	PR tree-optimization/83073
	PR tree-optimization/97909
	gcc/
	* fold-const.c (expr_not_equal_to): Use a multi-range class.

	gcc/testsuite/
	* gcc.dg/pr83072-2.c: New.
	* gcc.dg/pr83073.c: New.
---
 gcc/fold-const.c                 |  2 +-
 gcc/testsuite/gcc.dg/pr83072-2.c | 18 ++++++++++++++++++
 gcc/testsuite/gcc.dg/pr83073.c   | 10 ++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr83072-2.c
 create mode 100644 gcc/testsuite/gcc.dg/pr83073.c

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 397fa9a03a1..7945b8d9eda 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -10734,7 +10734,7 @@  tree_expr_nonzero_p (tree t)
 bool
 expr_not_equal_to (tree t, const wide_int &w)
 {
-  value_range vr;
+  int_range<5> vr;
   switch (TREE_CODE (t))
     {
     case INTEGER_CST:
diff --git a/gcc/testsuite/gcc.dg/pr83072-2.c b/gcc/testsuite/gcc.dg/pr83072-2.c
new file mode 100644
index 00000000000..f495f2582c4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr83072-2.c
@@ -0,0 +1,18 @@ 
+/* { dg-do compile} */
+/* { dg-options "-O2 -fdump-tree-evrp-details" } */
+
+int f1(int a, int b, int c){
+  if(c==0)__builtin_unreachable();
+  a *= c;
+  b *= c;
+  return a == b;
+}
+
+int f2(int a, int b, int c){
+  c |= 1;
+  a *= c;
+  b *= c;
+  return a == b;
+}
+
+/* { dg-final { scan-tree-dump-times "gimple_simplified to" 2 "evrp" } }  */
diff --git a/gcc/testsuite/gcc.dg/pr83073.c b/gcc/testsuite/gcc.dg/pr83073.c
new file mode 100644
index 00000000000..1168ae822a4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr83073.c
@@ -0,0 +1,10 @@ 
+/* { dg-do compile} */
+/* { dg-options "-O2 -fdump-tree-evrp-details -fno-tree-fre -fno-tree-ccp -fno-tree-forwprop" } */
+
+int f(int x)
+{
+    x = x|1;
+    return x & 1;
+}
+
+/* { dg-final { scan-tree-dump "gimple_simplified to.* = 1" "evrp" } }  */
-- 
2.17.2