From patchwork Thu Nov 4 08:19:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 47031 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 ABA64385803D for ; Thu, 4 Nov 2021 08:20:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABA64385803D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636014000; bh=JrECcngkcXtIQYeaxfBELoN8ScmWn3EwtJt3nVIrBmw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=hhh06SNW2ZcQJTpLTfY1bAICQw0QLgSvcXHSP+t3oKs39UlFp+VKpt8MVPb7JNYGF zg6078cabSO/Bl6ruy9qaUaPl9hxnqSg7JmB95L8rj1UtZDC5SVPIfeWc1/or9E7dL ivehKkjH77YXHKzOV5WyrvnMXWrlfjr/TNn0LzFw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 55EBB3858C3A for ; Thu, 4 Nov 2021 08:19:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 55EBB3858C3A Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BF51B1F782 for ; Thu, 4 Nov 2021 08:19:29 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A678113DA3 for ; Thu, 4 Nov 2021 08:19:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id q7CPJpGXg2HMHAAAMHmgww (envelope-from ) for ; Thu, 04 Nov 2021 08:19:29 +0000 Date: Thu, 4 Nov 2021 09:19:29 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] rtl-optimization/103075 - avoid ICEing on unfolded int-to-float converts Message-ID: <0o2r45o-6qso-4367-9ons-q9p0974243n8@fhfr.qr> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following avoids asserting in exact_int_to_float_conversion_p that the argument is not constant which it in fact can be with -frounding-math and inexact int-to-float conversions. Say so. Bootstrap & regtest running on x86_64-unknown-linux-gnu. 2021-11-04 Richard Biener PR rtl-optimization/103075 * simplify-rtx.c (exact_int_to_float_conversion_p): Return false for a VOIDmode operand. * gcc.dg/pr103075.c: New testcase. --- gcc/simplify-rtx.c | 8 +++++--- gcc/testsuite/gcc.dg/pr103075.c | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr103075.c diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index aac5693f548..23036aede81 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -899,10 +899,12 @@ simplify_context::simplify_unary_operation (rtx_code code, machine_mode mode, static bool exact_int_to_float_conversion_p (const_rtx op) { - int out_bits = significand_size (GET_MODE_INNER (GET_MODE (op))); machine_mode op0_mode = GET_MODE (XEXP (op, 0)); - /* Constants shouldn't reach here. */ - gcc_assert (op0_mode != VOIDmode); + /* Constants can reach here with -frounding-math, if they do then + the conversion isn't exact. */ + if (op0_mode == VOIDmode) + return false; + int out_bits = significand_size (GET_MODE_INNER (GET_MODE (op))); int in_prec = GET_MODE_UNIT_PRECISION (op0_mode); int in_bits = in_prec; if (HWI_COMPUTABLE_MODE_P (op0_mode)) diff --git a/gcc/testsuite/gcc.dg/pr103075.c b/gcc/testsuite/gcc.dg/pr103075.c new file mode 100644 index 00000000000..b332fb01434 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr103075.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O -frounding-math" } */ + +float +foo (void) +{ + return (float) 0x1699925 * 1.1; +}