[COMMITTED] Use nonzero bits in range-ops to determine if < 0 is false.
Commit Message
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.
---
gcc/range-op.cc | 3 +++
gcc/testsuite/g++.dg/ipa/pure-const-3.C | 2 +-
gcc/testsuite/gcc.dg/pr102983.c | 2 +-
3 files changed, 5 insertions(+), 2 deletions(-)
@@ -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;
@@ -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);
@@ -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;