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: 1704292 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=PT0NDLmM; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NBtkm58R9z23mL for ; Wed, 16 Nov 2022 17:42:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 28C223955606 for ; Wed, 16 Nov 2022 06:42:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 28C223955606 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668580926; bh=a5Xo/KAdZ0ks2FQ2QgpoVJWTba5zqV2Hp08UQn76CM0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=PT0NDLmMEol4sFAc7rZV7qRp2eMgAMT4ggxWnOwBDoow7BoaOXeJRzYP7G54iMaHo 12wB9Qq9iUY24bQvxoxSK8MZUptTyl6wmZAgv3p+ZpRTdLqVJ0FnYo1vd8L84RmWjL gfpXD84h6xcs9EETjP6JnWxlcCE1VOc29C8DDsUU= 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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; +}