* [COMMITTED] Clear nonzero mask when inverting ranges.
@ 2022-07-13 14:26 Aldy Hernandez
2022-07-13 14:26 ` [COMMITTED] Use nonzero bits in range-ops to determine if < 0 is false Aldy Hernandez
0 siblings, 1 reply; 2+ messages in thread
From: Aldy Hernandez @ 2022-07-13 14:26 UTC (permalink / raw)
To: GCC patches
Every time we set a range we should take into account the nonzero
mask. This happens automatically for the set() methods, plus all the
other assignment, intersect, and union methods. Unfortunately I
forgot about the invert code.
Also, for good measure I audited the rest of the setters in
value_range.cc and plugged the legacy code to pessimize the masks to
-1 for union/intersect, since we don't support the masks on them (or
rather, we don't keep very good track of them).
Tested on x86-64 Linux.
gcc/ChangeLog:
* value-range.cc (irange::copy_to_legacy): Set nonzero mask.
(irange::legacy_intersect): Clear nonzero mask.
(irange::legacy_union): Same.
(irange::invert): Same.
---
gcc/value-range.cc | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 2aa973b2af2..528ed547ef3 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -331,6 +331,7 @@ irange::copy_to_legacy (const irange &src)
m_base[0] = src.m_base[0];
m_base[1] = src.m_base[1];
m_kind = src.m_kind;
+ m_nonzero_mask = src.m_nonzero_mask;
return;
}
// Copy multi-range to legacy.
@@ -1336,6 +1337,9 @@ irange::legacy_intersect (irange *vr0, const irange *vr1)
intersect_ranges (&vr0kind, &vr0min, &vr0max,
vr1->kind (), vr1->min (), vr1->max ());
+ // Pessimize nonzero masks, as we don't support them.
+ m_nonzero_mask = NULL;
+
/* Make sure to canonicalize the result though as the inversion of a
VR_RANGE can still be a VR_RANGE. */
if (vr0kind == VR_UNDEFINED)
@@ -1657,6 +1661,9 @@ irange::legacy_union (irange *vr0, const irange *vr1)
union_ranges (&vr0kind, &vr0min, &vr0max,
vr1->kind (), vr1->min (), vr1->max ());
+ // Pessimize nonzero masks, as we don't support them.
+ m_nonzero_mask = NULL;
+
if (vr0kind == VR_UNDEFINED)
vr0->set_undefined ();
else if (vr0kind == VR_VARYING)
@@ -2253,6 +2260,7 @@ irange::invert ()
}
gcc_checking_assert (!undefined_p () && !varying_p ());
+ m_nonzero_mask = NULL;
// We always need one more set of bounds to represent an inverse, so
// if we're at the limit, we can't properly represent things.
--
2.36.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* [COMMITTED] Use nonzero bits in range-ops to determine if < 0 is false.
2022-07-13 14:26 [COMMITTED] Clear nonzero mask when inverting ranges Aldy Hernandez
@ 2022-07-13 14:26 ` Aldy Hernandez
0 siblings, 0 replies; 2+ messages in thread
From: Aldy Hernandez @ 2022-07-13 14:26 UTC (permalink / raw)
To: GCC patches
For a signed integer, x < 0 is false if the sign bit in the nonzero
bits of X is clear.
Both CCP and ipa-cp can set the global nonzero bits in a range, which
means we can now use some of that information in evrp and subsequent
passes. I've adjusted two tests which now fold things earlier because
of this optimization.
Tested on x86-64 Linux.
gcc/ChangeLog:
* range-op.cc (operator_lt::fold_range): Use nonzero bits.
gcc/testsuite/ChangeLog:
* g++.dg/ipa/pure-const-3.C: Adjust.
* gcc.dg/pr102983.c: Adjust.
---
gcc/range-op.cc | 3 +++
gcc/testsuite/g++.dg/ipa/pure-const-3.C | 2 +-
gcc/testsuite/gcc.dg/pr102983.c | 2 +-
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 0e16408027c..e184129f9af 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -803,6 +803,9 @@ operator_lt::fold_range (irange &r, tree type,
r = range_true (type);
else if (!wi::lt_p (op1.lower_bound (), op2.upper_bound (), sign))
r = range_false (type);
+ // Use nonzero bits to determine if < 0 is false.
+ else if (op2.zero_p () && !wi::neg_p (op1.get_nonzero_bits (), sign))
+ r = range_false (type);
else
r = range_true_and_false (type);
return true;
diff --git a/gcc/testsuite/g++.dg/ipa/pure-const-3.C b/gcc/testsuite/g++.dg/ipa/pure-const-3.C
index 172a36bedb5..b4a4673e86e 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" } */
+/* { 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);
diff --git a/gcc/testsuite/gcc.dg/pr102983.c b/gcc/testsuite/gcc.dg/pr102983.c
index ef58af6def0..e1bd24b2e39 100644
--- a/gcc/testsuite/gcc.dg/pr102983.c
+++ b/gcc/testsuite/gcc.dg/pr102983.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-evrp" } */
+/* { dg-options "-O2 -fdump-tree-evrp -fno-tree-ccp" } */
void foo(void);
static int a = 1;
--
2.36.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-07-13 14:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-13 14:26 [COMMITTED] Clear nonzero mask when inverting ranges Aldy Hernandez
2022-07-13 14:26 ` [COMMITTED] Use nonzero bits in range-ops to determine if < 0 is false 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).