]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use nonzero bits in range-ops to determine if < 0 is false.
authorAldy Hernandez <aldyh@redhat.com>
Tue, 12 Jul 2022 07:37:13 +0000 (09:37 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Wed, 13 Jul 2022 14:25:28 +0000 (16:25 +0200)
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
gcc/testsuite/g++.dg/ipa/pure-const-3.C
gcc/testsuite/gcc.dg/pr102983.c

index 0e16408027ceb5fdd0c64e6a61d0f0b8cf5fb659..e184129f9af7d87f632149f27401211166a77c60 100644 (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;
index 172a36bedb5b3df66b02a2eae6c0cc7574d43de9..b4a4673e86ea9daa2433cd9313c9159ea0d2eef1 100644 (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);
index ef58af6def08df562fa27ba1f135f675ec01e23e..e1bd24b2e39e31cc67a0198ccd2504069ec349ed 100644 (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;