* [COMMITTED] Normalize irange_bitmask before union/intersect.
@ 2023-07-17 7:16 Aldy Hernandez
2023-07-17 7:16 ` [COMMITTED] Add global setter for value/mask pair for SSA names Aldy Hernandez
0 siblings, 1 reply; 2+ messages in thread
From: Aldy Hernandez @ 2023-07-17 7:16 UTC (permalink / raw)
To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez
The bit twiddling in union/intersect for the value/mask pair must be
normalized to have the unknown bits with a value of 0 in order to make
the math simpler. Normalizing at construction slowed VRP by 1.5% so I
opted to normalize before updating the bitmask in range-ops, since it
was the only user. However, with upcoming changes there will be
multiple setters of the mask (IPA and CCP), so we need something more
general.
I played with various alternatives, and settled on normalizing before
union/intersect which were the ones needing the bits cleared. With
this patch, there's no noticeable difference in performance either in
VRP or in overall compilation.
gcc/ChangeLog:
* value-range.cc (irange_bitmask::verify_mask): Mask need not be
normalized.
* value-range.h (irange_bitmask::union_): Normalize beforehand.
(irange_bitmask::intersect): Same.
---
gcc/value-range.cc | 3 ---
gcc/value-range.h | 12 ++++++++++--
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 011bdbdeae6..2abf57bcee8 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -1953,9 +1953,6 @@ void
irange_bitmask::verify_mask () const
{
gcc_assert (m_value.get_precision () == m_mask.get_precision ());
- // Unknown bits must have their corresponding value bits cleared as
- // it simplifies union and intersect.
- gcc_assert (wi::bit_and (m_mask, m_value) == 0);
}
void
diff --git a/gcc/value-range.h b/gcc/value-range.h
index 0170188201b..d8af6fca7d7 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -211,8 +211,12 @@ irange_bitmask::operator== (const irange_bitmask &src) const
}
inline bool
-irange_bitmask::union_ (const irange_bitmask &src)
+irange_bitmask::union_ (const irange_bitmask &orig_src)
{
+ // Normalize mask.
+ irange_bitmask src (orig_src.m_value & ~orig_src.m_mask, orig_src.m_mask);
+ m_value &= ~m_mask;
+
irange_bitmask save (*this);
m_mask = (m_mask | src.m_mask) | (m_value ^ src.m_value);
m_value = m_value & src.m_value;
@@ -222,8 +226,12 @@ irange_bitmask::union_ (const irange_bitmask &src)
}
inline bool
-irange_bitmask::intersect (const irange_bitmask &src)
+irange_bitmask::intersect (const irange_bitmask &orig_src)
{
+ // Normalize mask.
+ irange_bitmask src (orig_src.m_value & ~orig_src.m_mask, orig_src.m_mask);
+ m_value &= ~m_mask;
+
irange_bitmask save (*this);
// If we have two known bits that are incompatible, the resulting
// bit is undefined. It is unclear whether we should set the entire
--
2.40.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* [COMMITTED] Add global setter for value/mask pair for SSA names.
2023-07-17 7:16 [COMMITTED] Normalize irange_bitmask before union/intersect Aldy Hernandez
@ 2023-07-17 7:16 ` Aldy Hernandez
0 siblings, 0 replies; 2+ messages in thread
From: Aldy Hernandez @ 2023-07-17 7:16 UTC (permalink / raw)
To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez
This patch provides a way to set the value/mask pair of known bits
globally, similarly to how we can use set_nonzero_bits for known 0
bits. This can then be used by CCP and IPA to set value/mask info
instead of throwing away the known 1 bits.
In further clean-ups, I will see if it makes sense to remove
set_nonzero_bits altogether, since it is subsumed by value/mask.
gcc/ChangeLog:
* tree-ssanames.cc (set_bitmask): New.
* tree-ssanames.h (set_bitmask): New.
---
gcc/tree-ssanames.cc | 15 +++++++++++++++
gcc/tree-ssanames.h | 1 +
2 files changed, 16 insertions(+)
diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index 5fdb6a37e9f..f54394363a0 100644
--- a/gcc/tree-ssanames.cc
+++ b/gcc/tree-ssanames.cc
@@ -465,6 +465,21 @@ set_nonzero_bits (tree name, const wide_int &mask)
set_range_info (name, r);
}
+/* Update the known bits of NAME.
+
+ Zero bits in MASK cover constant values. Set bits in MASK cover
+ unknown values. VALUE are the known bits. */
+
+void
+set_bitmask (tree name, const wide_int &value, const wide_int &mask)
+{
+ gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
+
+ int_range<2> r (TREE_TYPE (name));
+ r.update_bitmask (irange_bitmask (value, mask));
+ set_range_info (name, r);
+}
+
/* Return a widest_int with potentially non-zero bits in SSA_NAME
NAME, the constant for INTEGER_CST, or -1 if unknown. */
diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h
index f3fa609208a..b5e3f228ee8 100644
--- a/gcc/tree-ssanames.h
+++ b/gcc/tree-ssanames.h
@@ -59,6 +59,7 @@ struct GTY(()) ptr_info_def
/* Sets the value range to SSA. */
extern bool set_range_info (tree, const vrange &);
extern void set_nonzero_bits (tree, const wide_int &);
+extern void set_bitmask (tree, const wide_int &value, const wide_int &mask);
extern wide_int get_nonzero_bits (const_tree);
extern bool ssa_name_has_boolean_range (tree);
extern void init_ssanames (struct function *, int);
--
2.40.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-17 7:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-17 7:16 [COMMITTED] Normalize irange_bitmask before union/intersect Aldy Hernandez
2023-07-17 7:16 ` [COMMITTED] Add global setter for value/mask pair for SSA names 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).