public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1685] Use nonzero bits in range-ops to determine if < 0 is false.
Date: Wed, 13 Jul 2022 14:26:16 +0000 (GMT)	[thread overview]
Message-ID: <20220713142616.82DD4383A370@sourceware.org> (raw)

https://gcc.gnu.org/g:1184f677d6e17033572ecc5e97ea5ee627627908

commit r13-1685-g1184f677d6e17033572ecc5e97ea5ee627627908
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Jul 12 09:37:13 2022 +0200

    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.

Diff:
---
 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(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 0e16408027c..e184129f9af 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -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;
diff --git a/gcc/testsuite/g++.dg/ipa/pure-const-3.C b/gcc/testsuite/g++.dg/ipa/pure-const-3.C
index 172a36bedb5..b4a4673e86e 100644
--- a/gcc/testsuite/g++.dg/ipa/pure-const-3.C
+++ b/gcc/testsuite/g++.dg/ipa/pure-const-3.C
@@ -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);
diff --git a/gcc/testsuite/gcc.dg/pr102983.c b/gcc/testsuite/gcc.dg/pr102983.c
index ef58af6def0..e1bd24b2e39 100644
--- a/gcc/testsuite/gcc.dg/pr102983.c
+++ b/gcc/testsuite/gcc.dg/pr102983.c
@@ -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;


                 reply	other threads:[~2022-07-13 14:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220713142616.82DD4383A370@sourceware.org \
    --to=aldyh@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).