[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.
This commit is contained in:
Aldy Hernandez 2023-07-06 10:55:46 +02:00
parent 137fb7077f
commit 7a5e476589
2 changed files with 30 additions and 0 deletions

View file

@ -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 ())
{

View file

@ -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" } }