Use nonzero bits in range-ops to determine if < 0 is false.

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.
This commit is contained in:
Aldy Hernandez 2022-07-12 09:37:13 +02:00
parent 554b21edb9
commit 1184f677d6
3 changed files with 5 additions and 2 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;