From patchwork Fri Feb 4 23:07:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 50813 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 5D59B3858C2D for ; Fri, 4 Feb 2022 23:08:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D59B3858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644016106; bh=9YFAQOEo+q277k4OMpXauuern7EKkkX2jrKSD1cDAlg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=yFGGFDk4xU4JKnePXvECxCmWBY/i5pZ+PTe32SheQPnirU92x2xuD2mYWkDVX+FT7 9O0FuOj/pamBBcilhdla9lrUMPPIwaw56MSTtzdNCuXHaxzKBGcUcaas22webMRnVv hP5Biu6K5YsKmXbj9SQmFg1QyLUOd8hSMcR9ep8Y= 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 AEACB3858D20 for ; Fri, 4 Feb 2022 23:07:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AEACB3858D20 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-620-px-aSVI3Ppuwx8keA2w6tg-1; Fri, 04 Feb 2022 18:07:33 -0500 X-MC-Unique: px-aSVI3Ppuwx8keA2w6tg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5178B100CCC1; Fri, 4 Feb 2022 23:07:32 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E0035E2C3; Fri, 4 Feb 2022 23:07:31 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 214N7SYl2027492 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 5 Feb 2022 00:07:29 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 214N7RrX2027491; Sat, 5 Feb 2022 00:07:27 +0100 Date: Sat, 5 Feb 2022 00:07:27 +0100 To: Richard Biener , Jeff Law Subject: [PATCH] match.pd: Fix x * 0.0 -> 0.0 folding [PR104389] Message-ID: <20220204230727.GP2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The recent PR95115 change to punt in const_binop on folding operation with non-NaN operands into NaN if flag_trapping_math broke the following testcase, because the x * 0.0 simplification punts just if x maybe a NaN (because NaN * 0.0 is NaN not 0.0) or if one of the operands could be negative zero. But Inf * 0.0 or -Inf * 0.0 is also NaN, not 0.0, so when NaNs are honored we need to punt for possible infinities too. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and 11/10 where the PR95115 change has been unfortunately backported to as well? 2022-02-04 Jakub Jelinek PR tree-optimization/104389 (x * 0 -> 0): Punt if x maybe infinite and NaNs are honored. * gcc.dg/pr104389.c: New test. Jakub --- gcc/match.pd.jj 2022-02-04 14:36:55.393599880 +0100 +++ gcc/match.pd 2022-02-04 20:30:48.548213594 +0100 @@ -256,10 +256,12 @@ (define_operator_list SYNC_FETCH_AND_AND /* Maybe fold x * 0 to 0. The expressions aren't the same when x is NaN, since x * 0 is also NaN. Nor are they the same in modes with signed zeros, since multiplying a - negative value by 0 gives -0, not +0. */ + negative value by 0 gives -0, not +0. Nor when x is +-Inf, + since x * 0 is NaN. */ (simplify (mult @0 real_zerop@1) (if (!tree_expr_maybe_nan_p (@0) + && (!HONOR_NANS (type) || !tree_expr_maybe_infinite_p (@0)) && !tree_expr_maybe_real_minus_zero_p (@0) && !tree_expr_maybe_real_minus_zero_p (@1)) @1)) --- gcc/testsuite/gcc.dg/pr104389.c.jj 2022-02-04 20:37:40.579537142 +0100 +++ gcc/testsuite/gcc.dg/pr104389.c 2022-02-04 20:37:20.787809803 +0100 @@ -0,0 +1,26 @@ +/* PR tree-optimization/104389 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ +/* { dg-add-options ieee } */ +/* { dg-require-effective-target inf } */ + +__attribute__((noipa)) double +foo (void) +{ + double a = __builtin_huge_val (); + return a * 0.0; +} + +__attribute__((noipa)) long double +bar (void) +{ + return __builtin_huge_vall () * 0.0L; +} + +int +main () +{ + if (!__builtin_isnan (foo ()) || !__builtin_isnanl (bar ())) + __builtin_abort (); + return 0; +}