From patchwork Mon Dec 5 18:35:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 61484 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 199AD385220D for ; Mon, 5 Dec 2022 22:37:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 199AD385220D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670279861; bh=sfUZsS/3XI5bqxR9SQ0R3UX5trIboI+efIB2wdqNuec=; h=Resent-From:Resent-Date:Resent-To:Date:To:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=VTV2FX9nee5yVGsnLgylEBthcrSqoTq43bVAIH229arDVIYhjlSIC85C00yu1hQOO d2uXP6DQYfZ7oE8rE0lE092el1l4snkcqmavyZNnnZIqKn3q4CWZrBEmtBXNAq2DyE 9C9goFXbWsGSeI+dbeEG9XyS0DXVm35y6ebDO+N8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id EB3AF385B1B3 for ; Mon, 5 Dec 2022 22:37:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EB3AF385B1B3 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-424-sKQIy_3aP9Ko0LH6Aweodw-1; Mon, 05 Dec 2022 17:37:10 -0500 X-MC-Unique: sKQIy_3aP9Ko0LH6Aweodw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4BA6A101A54E; Mon, 5 Dec 2022 22:37:10 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0CD7C1121325; Mon, 5 Dec 2022 22:37:09 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2B5Mb5lN3424795 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 5 Dec 2022 23:37:05 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2B5Mb4oH3424794; Mon, 5 Dec 2022 23:37:04 +0100 Resent-From: Jakub Jelinek Resent-Date: Mon, 5 Dec 2022 23:37:04 +0100 Resent-Message-ID: Resent-To: Richard Biener , Aldy Hernandez , gcc-patches@gcc.gnu.org Date: Mon, 5 Dec 2022 19:35:46 +0100 To: Richard Biener , Aldy Hernandez Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] range-op-float: Fix up ICE in lower_bound [PR107975] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 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. Jakub --- 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; +}