public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>, Aldy Hernandez <aldyh@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] range-op-float: Fix up ICE in lower_bound [PR107975]
Date: Mon, 5 Dec 2022 19:35:46 +0100	[thread overview]
Message-ID: <Y446AHZfl9DZFrdx@tucnak> (raw)

Hi!

According to https://gcc.gnu.org/pipermail/gcc-regression/2022-December/077258.html
my patch caused some ICEs, e.g. the following testcase ICEs.
The problem is that lower_bound and upper_bound methods on a france assert
that the range isn't VR_NAN or VR_UNDEFINED.
All the op1_range/op2_range methods already return early if lhs.undefined_p,
but the other cases (when lhs is VR_NAN or the other opN is VR_NAN or
VR_UNDEFINED) aren't.  float_binary_op_range_finish will DTRT for those
cases already.

Ok for trunk if this passes bootstrap/regtest?

2022-12-05  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/107975
	* range-op-float.cc (foperator_mult::op1_range,
	foperator_div::op1_range, foperator_div::op2_range): Just
	return float_binary_op_range_finish result if lhs is known
	NAN, or the other operand is known NAN or UNDEFINED.

	* gcc.dg/pr107975.c: New test.

--- gcc/range-op-float.cc.jj	2022-12-05 11:17:34.900573272 +0100
+++ gcc/range-op-float.cc	2022-12-05 17:58:38.059754128 +0100
@@ -2146,6 +2146,8 @@ public:
     bool ret = rdiv.fold_range (r, type, lhs, op2);
     if (ret == false)
       return false;
+    if (lhs.known_isnan () || op2.known_isnan () || op2.undefined_p ())
+      return float_binary_op_range_finish (ret, r, type, lhs);
     const REAL_VALUE_TYPE &lhs_lb = lhs.lower_bound ();
     const REAL_VALUE_TYPE &lhs_ub = lhs.upper_bound ();
     const REAL_VALUE_TYPE &op2_lb = op2.lower_bound ();
@@ -2296,6 +2298,8 @@ public:
     bool ret = fop_mult.fold_range (r, type, lhs, op2);
     if (!ret)
       return ret;
+    if (lhs.known_isnan () || op2.known_isnan () || op2.undefined_p ())
+      return float_binary_op_range_finish (ret, r, type, lhs);
     const REAL_VALUE_TYPE &lhs_lb = lhs.lower_bound ();
     const REAL_VALUE_TYPE &lhs_ub = lhs.upper_bound ();
     const REAL_VALUE_TYPE &op2_lb = op2.lower_bound ();
@@ -2325,6 +2329,8 @@ public:
     bool ret = fold_range (r, type, op1, lhs);
     if (!ret)
       return ret;
+    if (lhs.known_isnan () || op1.known_isnan () || op1.undefined_p ())
+      return float_binary_op_range_finish (ret, r, type, lhs);
     const REAL_VALUE_TYPE &lhs_lb = lhs.lower_bound ();
     const REAL_VALUE_TYPE &lhs_ub = lhs.upper_bound ();
     const REAL_VALUE_TYPE &op1_lb = op1.lower_bound ();
--- gcc/testsuite/gcc.dg/pr107975.c.jj	2022-12-05 19:15:56.518851401 +0100
+++ gcc/testsuite/gcc.dg/pr107975.c	2022-12-05 19:15:04.014620281 +0100
@@ -0,0 +1,15 @@
+/* PR tree-optimization/107975 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-add-options ieee } */
+
+double
+foo (double x, double y)
+{
+  if (x == 42.0)
+    return 1.0;
+  double r = x * y;
+  if (!__builtin_isnan (r))
+    __builtin_unreachable ();
+  return r;
+}

	Jakub


             reply	other threads:[~2022-12-05 22:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05 18:35 Jakub Jelinek [this message]
2022-12-06  7:17 ` Richard Biener
2022-12-06 19:04 ` Toon Moene

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=Y446AHZfl9DZFrdx@tucnak \
    --to=jakub@redhat.com \
    --cc=aldyh@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /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).