public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew MacLeod <amacleod@redhat.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [COMMITTED] PR tree-optimization/106687 - Return the correct relation
Date: Mon, 22 Aug 2022 21:06:17 -0400	[thread overview]
Message-ID: <9241ba5f-224f-3f36-78a8-3890f43711d7@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 303 bytes --]

With an input condition of op1 > op2, and evaluating the unsigned 
expression:
     LHS = op1 - op2
range-ops was returning LHS < op1 , which is incorrect as op2 could be 
zero.  This patch adjusts it to return LHS <= op1.

Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed.

Andrew

[-- Attachment #2: 687.diff --]
[-- Type: text/x-patch, Size: 1611 bytes --]

commit de6d9e0b3d5c08896cbf047b299fc7f8d1e42be7
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Mon Aug 22 15:40:48 2022 -0400

    Return the correct relation
    
    With an input condition of op1 > op2, and evaluating the unsigned expression:
    LHS = op1 - op2
    range-ops was returning LHS < op1 , which is incorrect as op2 coould be
    zero.  This patch adjusts it to return LHS <= op1.
    
            PR tree-optimization/106687
            gcc/
            * range-op.cc (operator_minus::lhs_op1_relation): Return VREL_LE
            for the VREL_GT case as well.
    
            gcc/testsuite/
            * g++.dg/pr106687.C: New.

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index dfdd971c90a..806edf1012e 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -1378,7 +1378,6 @@ operator_minus::lhs_op1_relation (const irange &, const irange &op1,
     switch (rel)
       {
       case VREL_GT:
-	return VREL_LT;
       case VREL_GE:
 	return VREL_LE;
       default:
diff --git a/gcc/testsuite/g++.dg/pr106687.C b/gcc/testsuite/g++.dg/pr106687.C
new file mode 100644
index 00000000000..75ac81c216c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr106687.C
@@ -0,0 +1,22 @@
+// { dg-do run }
+// { dg-options "-O2"  }
+
+bool var_0 = (bool)0;
+unsigned int var_7 = 42;
+char var_215;
+
+int main() {
+    unsigned b = var_0;
+    unsigned p2 = var_7;
+    unsigned *tp;
+    if (b < p2)
+      tp = &p2;
+    else
+      tp = &b;
+    unsigned tt = *tp;
+    unsigned t = tt ^ (var_7 - var_0);
+    var_215 = t ? t : 42;
+    if (var_215 != 42)
+      __builtin_abort();
+    return 0;
+}

                 reply	other threads:[~2022-08-23  1:06 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=9241ba5f-224f-3f36-78a8-3890f43711d7@redhat.com \
    --to=amacleod@redhat.com \
    --cc=gcc-patches@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).