From patchwork Wed Nov 16 06:41:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 20735 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3123110wru; Tue, 15 Nov 2022 22:42:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf4f8FPFuH8EWq+gartMzrNcKUgRQUrqsQXO43R3rlVeAGNgcCVX6U8nsQmtWO2i7Z8YMa/r X-Received: by 2002:a17:907:9a85:b0:7ad:b45c:dbca with SMTP id km5-20020a1709079a8500b007adb45cdbcamr16909152ejc.388.1668580951660; Tue, 15 Nov 2022 22:42:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668580951; cv=none; d=google.com; s=arc-20160816; b=GbH5mXseCpiWz9CL5w/1DFbWsRuDIN7bkfumP0W92gSt8WDsXKhsOrd7z7dy3XiWoW WqYLMfdWbEqWn7n5d7hV2audL+HIRtdhnhE8HZANzcq/C7rmkWmJQOjyd+A0/F5ZKDKy EzpTAvyl+FOWTOXKol1XhCoVh8qbN+nq3eCdVfynLjr/4OITutc0/Ec/4gBNGQwe3Z33 Nhs0xL9ylnps0wmUlhBV319KEv6HPRbmRmIeP7EMOiXjGEu1p3/UdWwhiG00sVN08ipt I/EpST+UzRZ/SgwWGnk3eFo1A+35wqtL2zatEanUuJ6SOl1A7wdQWMDwjbn/MWKCuXGk j3HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=a5Xo/KAdZ0ks2FQ2QgpoVJWTba5zqV2Hp08UQn76CM0=; b=Bt7RX18bPtBJRVoAwCK8AnC9yK0puRoInW0LryRbH2U8HDrascmi15v93SmCABY3xa Lajc0VhIgVuUHOXrpUjk8cT+SFKlTEuBFTaj6U4hznK+HAFjcwpbfYNtvckT4s2YuQuX 67CgJEjcHMfhLgu5SYj5wefDMHU0p0JjQ242msJDFCBHPawDg7ffAZSj9A6JmKDRYnBf 7igUiWpXL5+iCNIrajbQOwVD0gmxi5fwwk5GMZAxkASrZW3kkwaLx/ik0LqO2M1IfeVG PWGjhHOk2qLQjL7/i00tBehXH7ks/t7llwxUUnoptz525PGL1iv5p2MmzQaZZLwQkT5Y QLdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lhQXowNk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id m19-20020a056402511300b0045d46f28533si14811009edd.377.2022.11.15.22.42.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 22:42:31 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lhQXowNk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D9723954C63 for ; Wed, 16 Nov 2022 06:42:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D9723954C63 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668580949; bh=a5Xo/KAdZ0ks2FQ2QgpoVJWTba5zqV2Hp08UQn76CM0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=lhQXowNkqGuAOm/SOg9MJyYCyeugJ/fX8QjiaBJv7D2GD1oocXwDL+sUovAZsOuLl wAHryAT9Ic2EvSvPNQxcQUfy3Oih5oxeTt94BSjWMNkM9nZPIXjurgFuMSIFX5cXE5 3Ep9nzJDH7CZEdHlTwM/Ps7rdTPDYEerXCnrbKq8= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id C0E563955626 for ; Wed, 16 Nov 2022 06:41:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C0E563955626 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-653-eW5GT0RKNgGnWjJowUYV9w-1; Wed, 16 Nov 2022 01:41:39 -0500 X-MC-Unique: eW5GT0RKNgGnWjJowUYV9w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DAD5E101AA4A for ; Wed, 16 Nov 2022 06:41:38 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9CCBC492B05 for ; Wed, 16 Nov 2022 06:41:38 +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 2AG6fYFG2448786 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Wed, 16 Nov 2022 07:41:34 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2AG6fX0M2448785 for gcc-patches@gcc.gnu.org; Wed, 16 Nov 2022 07:41:33 +0100 Date: Wed, 16 Nov 2022 07:41:33 +0100 To: gcc-patches@gcc.gnu.org Subject: [committed] range-op-float: Fix up float_binary_op_range_finish [PR107668] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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, 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749633940056079643?= X-GMAIL-MSGID: =?utf-8?q?1749633940056079643?= Hi! The following testcase ICEs, because when !HONOR_NANS but HONOR_SIGNED_ZEROS, if we see lhs = op1 * op2; and know that lhs is [-0.0, 0.0] and op2 is [0.0, 0.0], the division of these two yields UNDEFINED and clear_nan () on it fails an assert. With HONOR_NANS it would actually result in a known NAN, but when NANs aren't honored, we clear the NAN bits. Now, for the above case we actually don't know anything about the op1 range (except that it isn't a NAN/INF because of !HONOR_NANS !HONOR_INFINITIES), so I think the best is just to return VARYING for the case we get UNDEFINED as well. If we want, the op[12]_range methods perhaps can handle the corner cases earlier separately, say for lhs [0.0, 0.0] and op2 [0.0, 0.0] when HONOR_SIGNED_ZEROS this would be just [0.0, MAX]. Bootstrapped/regtested on x86_64-linux and i686-linux, preapproved by Aldy in the PR, committed to trunk. 2022-11-16 Jakub Jelinek PR tree-optimization/107668 * range-op-float.cc (float_binary_op_range_finish): Set VARYING also when r is UNDEFINED. * gcc.dg/ubsan/pr107668.c: New test. Jakub --- gcc/range-op-float.cc.jj 2022-11-14 19:33:32.514881313 +0100 +++ gcc/range-op-float.cc 2022-11-15 09:25:57.956137343 +0100 @@ -1891,8 +1891,9 @@ float_binary_op_range_finish (bool ret, // or the reverse operation introduced a known NAN. // Say for lhs = op1 * op2 if lhs is [-0, +0] and op2 is too, // 0 / 0 is known NAN. Just punt in that case. + // If NANs aren't honored, we get for 0 / 0 UNDEFINED, so punt as well. // Or if lhs is a known NAN, we also don't know anything. - if (r.known_isnan () || lhs.known_isnan ()) + if (r.known_isnan () || lhs.known_isnan () || r.undefined_p ()) { r.set_varying (type); return true; --- gcc/testsuite/gcc.dg/ubsan/pr107668.c.jj 2022-11-15 09:24:40.281189629 +0100 +++ gcc/testsuite/gcc.dg/ubsan/pr107668.c 2022-11-15 09:24:40.281189629 +0100 @@ -0,0 +1,12 @@ +/* PR tree-optimization/107668 */ +/* { dg-do compile } */ +/* { dg-options "-ffast-math -fno-associative-math -fsanitize=float-cast-overflow -fno-guess-branch-probability -fsigned-zeros" } */ + +_Complex int c; +int i; + +void +foo (void) +{ + c /= (_Complex) i; +}