* [COMMITTED] [range-op] Enable value/mask propagation in range-op.
@ 2023-07-12 16:21 Aldy Hernandez
0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2023-07-12 16:21 UTC (permalink / raw)
To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez
Throw the switch in range-ops to make full use of the value/mask
information instead of only the nonzero bits. This will cause most of
the operators implemented in range-ops to use the value/mask
information calculated by CCP's bit_value_binop() function which
range-ops uses. This opens up more optimization opportunities.
In follow-up patches I will change the global range setter
(set_range_info) to be able to save the value/mask pair, and make both
CCP and IPA be able to save the known ones bit info, instead of
throwing it away.
gcc/ChangeLog:
* range-op.cc (irange_to_masked_value): Remove.
(update_known_bitmask): Update irange value/mask pair instead of
only updating nonzero bits.
gcc/testsuite/ChangeLog:
* gcc.dg/pr83073.c: Adjust testcase.
---
gcc/range-op.cc | 53 ++++++++++++++--------------------
gcc/testsuite/gcc.dg/pr83073.c | 2 +-
2 files changed, 23 insertions(+), 32 deletions(-)
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index cb584314f4c..56e80c9f3ae 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -367,23 +367,6 @@ range_op_handler::op1_op2_relation (const vrange &lhs) const
}
-// Convert irange bitmasks into a VALUE MASK pair suitable for calling CCP.
-
-static void
-irange_to_masked_value (const irange &r, widest_int &value, widest_int &mask)
-{
- if (r.singleton_p ())
- {
- mask = 0;
- value = widest_int::from (r.lower_bound (), TYPE_SIGN (r.type ()));
- }
- else
- {
- mask = widest_int::from (r.get_nonzero_bits (), TYPE_SIGN (r.type ()));
- value = 0;
- }
-}
-
// Update the known bitmasks in R when applying the operation CODE to
// LH and RH.
@@ -391,25 +374,33 @@ void
update_known_bitmask (irange &r, tree_code code,
const irange &lh, const irange &rh)
{
- if (r.undefined_p () || lh.undefined_p () || rh.undefined_p ())
+ if (r.undefined_p () || lh.undefined_p () || rh.undefined_p ()
+ || r.singleton_p ())
return;
- widest_int value, mask, lh_mask, rh_mask, lh_value, rh_value;
+ widest_int widest_value, widest_mask;
tree type = r.type ();
signop sign = TYPE_SIGN (type);
int prec = TYPE_PRECISION (type);
- signop lh_sign = TYPE_SIGN (lh.type ());
- signop rh_sign = TYPE_SIGN (rh.type ());
- int lh_prec = TYPE_PRECISION (lh.type ());
- int rh_prec = TYPE_PRECISION (rh.type ());
-
- irange_to_masked_value (lh, lh_value, lh_mask);
- irange_to_masked_value (rh, rh_value, rh_mask);
- bit_value_binop (code, sign, prec, &value, &mask,
- lh_sign, lh_prec, lh_value, lh_mask,
- rh_sign, rh_prec, rh_value, rh_mask);
- wide_int tmp = wide_int::from (value | mask, prec, sign);
- r.set_nonzero_bits (tmp);
+ irange_bitmask lh_bits = lh.get_bitmask ();
+ irange_bitmask rh_bits = rh.get_bitmask ();
+
+ bit_value_binop (code, sign, prec, &widest_value, &widest_mask,
+ TYPE_SIGN (lh.type ()),
+ TYPE_PRECISION (lh.type ()),
+ widest_int::from (lh_bits.value (), sign),
+ widest_int::from (lh_bits.mask (), sign),
+ TYPE_SIGN (rh.type ()),
+ TYPE_PRECISION (rh.type ()),
+ widest_int::from (rh_bits.value (), sign),
+ widest_int::from (rh_bits.mask (), sign));
+
+ wide_int mask = wide_int::from (widest_mask, prec, sign);
+ wide_int value = wide_int::from (widest_value, prec, sign);
+ // Bitmasks must have the unknown value bits cleared.
+ value &= ~mask;
+ irange_bitmask bm (value, mask);
+ r.update_bitmask (bm);
}
// Return the upper limit for a type.
diff --git a/gcc/testsuite/gcc.dg/pr83073.c b/gcc/testsuite/gcc.dg/pr83073.c
index 1168ae822a4..228e1890086 100644
--- a/gcc/testsuite/gcc.dg/pr83073.c
+++ b/gcc/testsuite/gcc.dg/pr83073.c
@@ -7,4 +7,4 @@ int f(int x)
return x & 1;
}
-/* { dg-final { scan-tree-dump "gimple_simplified to.* = 1" "evrp" } } */
+/* { dg-final { scan-tree-dump "Folded into: return 1;" "evrp" } } */
--
2.40.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-12 16:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-12 16:21 [COMMITTED] [range-op] Enable value/mask propagation in range-op 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).