public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-2480] [range-op] Take known mask into account for bitwise ands [PR107043]
@ 2023-07-12 21:16 Aldy Hernandez
0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2023-07-12 21:16 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:7a5e47658904de9dc90f1292f3f69769177706f9
commit r14-2480-g7a5e47658904de9dc90f1292f3f69769177706f9
Author: Aldy Hernandez <aldyh@redhat.com>
Date: Thu Jul 6 10:55:46 2023 +0200
[range-op] Take known mask into account for bitwise ands [PR107043]
PR tree-optimization/107043
gcc/ChangeLog:
* range-op.cc (operator_bitwise_and::op1_range): Update bitmask.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr107043.c: New test.
Diff:
---
gcc/range-op.cc | 8 ++++++++
gcc/testsuite/gcc.dg/tree-ssa/pr107043.c | 22 ++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 56e80c9f3ae..6b5d4f2accd 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3463,6 +3463,14 @@ operator_bitwise_and::op1_range (irange &r, tree type,
if (r.undefined_p ())
set_nonzero_range_from_mask (r, type, lhs);
+ // For MASK == op1 & MASK, all the bits in MASK must be set in op1.
+ wide_int mask;
+ if (lhs == op2 && lhs.singleton_p (mask))
+ {
+ r.update_bitmask (irange_bitmask (mask, ~mask));
+ return true;
+ }
+
// For 0 = op1 & MASK, op1 is ~MASK.
if (lhs.zero_p () && op2.singleton_p ())
{
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107043.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107043.c
new file mode 100644
index 00000000000..af5df225746
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107043.c
@@ -0,0 +1,22 @@
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-evrp" }
+
+int g0(int n)
+{
+ int n1 = n & 0x8000;
+ if (n1 == 0)
+ return 1;
+ // n1 will be 0x8000 here.
+ return (n1 >> 15) & 0x1;
+}
+
+int g1(int n)
+{
+ int n1 = n & 0x8000;
+ if (n1 == 0)
+ return 1;
+ // n>>15 will be xxxxxx1 here.
+ return (n >> 15) & 0x1;
+}
+
+// { dg-final { scan-tree-dump-times "return 1;" 2 "evrp" } }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-12 21:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-12 21:16 [gcc r14-2480] [range-op] Take known mask into account for bitwise ands [PR107043] 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).