From patchwork Thu Sep 1 07:08:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp118892wro; Thu, 1 Sep 2022 00:09:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR79nhVXvrojSAGnLtgSF3bN1MJLCltmxqhWWEHTJddXhWQCqmGwLyvCWx6Ahc0L8roG/1+s X-Received: by 2002:a17:907:a0c7:b0:739:7ea:88ec with SMTP id hw7-20020a170907a0c700b0073907ea88ecmr22684931ejc.363.1662016150639; Thu, 01 Sep 2022 00:09:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662016150; cv=none; d=google.com; s=arc-20160816; b=CB7oE40j6/d9TsFNOtvRw5kM9zQRve0W5Wg/HIFzcH0d1ffPL8CSXQtt82l3L1UzrT 4jegmnaI9WrZrG/znKnKVnwFdxgEVHi1aQT3Ku0pYsQpMsogF1gFeKWI5dmplht6ENeN M9Zw0Dh5l7KB66CJIDcBmpJBVoSChFtLWWMMRQ+Vh3aChRsRgDRB892YQnYxkcb+4c3+ paGeBqlSA3c2d7RtXPcwxuhrKE+cYcLUfT/8UTQdaWNI6k4Hz9ycRRADrlFYc2QoYOQ0 yd5zgtzqtE8UHThgksd2eeLjJpxc8jUPDQHwk9EraSuJLxUdbJ8tv9tyBThPjZw8jHzW LduQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=VwgwnTw7Up2EvKMj+CIbzwxzc+7uNv/lER5VxapoKqc=; b=YMi8bDRQwj4WXKOChA6d1X5WBDsTaxU7tD3s0NKJuaXo2eTjMn7xA9vFYKR5VO7pew B84jyNRTKPvp6qHVKKCgD1tuMAwZIQXwtfjgF8WHZNg1f7Efz31sFutY8xpXwz7vuEIh 5BYuDOX+6TBnDZTZDcZLL5XJfJ86ve3KfejjuDca8pY78oIdrgCJ+70zvyoq9Mk1fwqO OKG/06DoxlpvUgNb9tUcoV5c4mNa/ipkxqvJBGFJglfIvsclDdqHnspO0L/kssCbrY7C tvo3qZBfsXMuGj3DLMSjLnvNCXpQVDLcdKZpY3KmMWGNhKf7nuY6QLT7lipPV5G31+3E xM1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kXvyktXb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id hb41-20020a170907162900b00730a134ccfasi12125986ejc.572.2022.09.01.00.09.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 00:09:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kXvyktXb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 98106382DB1D for ; Thu, 1 Sep 2022 07:09:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98106382DB1D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662016149; bh=VwgwnTw7Up2EvKMj+CIbzwxzc+7uNv/lER5VxapoKqc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=kXvyktXbGLLa2O2DXwwJJ49W/CDmug3v38ssKwQ7kNo5EnwzUVtDn6H/k+EhumBYN YzjXfl9Fi4n8DTLj9dYCi3j6+5FNqETcfS/ZR/7TfNIES3qmv/H5AAIR/5qNWjrV+Z LBFCNLYUwv1SMEd57flCn5wxe4I+ZQqVaufSRX5c= 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 44A6B3853558 for ; Thu, 1 Sep 2022 07:08:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 44A6B3853558 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-346-WIxpOuuVN6yV2MtOM8OvgA-1; Thu, 01 Sep 2022 03:08:22 -0400 X-MC-Unique: WIxpOuuVN6yV2MtOM8OvgA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9CBA785A58A for ; Thu, 1 Sep 2022 07:08:22 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.200]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3CAB62166B26; Thu, 1 Sep 2022 07:08:22 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 28178JPc2517852 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 1 Sep 2022 09:08:19 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 28178I3n2517851; Thu, 1 Sep 2022 09:08:18 +0200 To: GCC patches Subject: [COMMITTED] Make frange selftests work on !HONOR_NANS systems. Date: Thu, 1 Sep 2022 09:08:14 +0200 Message-Id: <20220901070814.2517831-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Cc: 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?1742750247294494446?= X-GMAIL-MSGID: =?utf-8?q?1742750247294494446?= I'm just shuffling the FP self tests here, with no change to existing functionality. If we agree that explicit NANs in the source code with !HONOR_NANS should behave any differently, I'm happy to address whatever needs fixing, but for now I'd like to unblock the !HONOR_NANS build systems. I have added an adaptation of a test Jakub suggested we handle in the PR: void funk(int cond) { float x; if (cond) x = __builtin_nan (""); else x = 1.24; bar(x); } For !HONOR_NANS, the range for the PHI of x_1 is the union of 1.24 and NAN which is really 1.24 with a maybe NAN. This reflects the IL-- the presence of the actual NAN. However, VRP will propagate this because it sees the 1.24 and ignores the possibility of a NAN, per !HONOR_NANS. IMO, this is correct. OTOH, for HONOR_NANS the unknown NAN property keeps us from propagating the value. Is there a reason we don't warn for calls to __builtin_nan when !HONOR_NANS? That makes no sense to me. PR tree-optimization/106785 gcc/ChangeLog: * value-range.cc (range_tests_nan): Adjust tests for !HONOR_NANS. (range_tests_floats): Same. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/vrp-float-nan-1.c: New test. --- .../gcc.dg/tree-ssa/vrp-float-nan-1.c | 18 +++++++++++++++ gcc/value-range.cc | 23 +++++++++++-------- 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-float-nan-1.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-nan-1.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-nan-1.c new file mode 100644 index 00000000000..126949b2b4c --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-nan-1.c @@ -0,0 +1,18 @@ +// { dg-do compile } +// { dg-options "-O2 -ffinite-math-only -fdump-tree-evrp" } + +void bar(float); + +void funk(int cond) +{ + float x; + + if (cond) + x = __builtin_nan (""); + else + x = 1.24; + + bar(x); +} + +// { dg-final { scan-tree-dump-times "bar \\(1.24" 1 "evrp" } } diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 473139c6dbd..3c7d4cb84b9 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -3535,13 +3535,16 @@ range_tests_nan () REAL_VALUE_TYPE q, r; // Equal ranges but with differing NAN bits are not equal. - r1 = frange_float ("10", "12"); - r0 = r1; - ASSERT_EQ (r0, r1); - r0.set_nan (fp_prop::NO); - ASSERT_NE (r0, r1); - r0.set_nan (fp_prop::YES); - ASSERT_NE (r0, r1); + if (HONOR_NANS (float_type_node)) + { + r1 = frange_float ("10", "12"); + r0 = r1; + ASSERT_EQ (r0, r1); + r0.set_nan (fp_prop::NO); + ASSERT_NE (r0, r1); + r0.set_nan (fp_prop::YES); + ASSERT_NE (r0, r1); + } // NAN ranges are not equal to each other. r0 = frange_nan (float_type_node); @@ -3624,9 +3627,11 @@ range_tests_floats () if (HONOR_SIGNED_ZEROS (float_type_node)) range_tests_signed_zeros (); - // A range of [-INF,+INF] is actually VARYING... + // A range of [-INF,+INF] is actually VARYING if no other properties + // are set. r0 = frange_float ("-Inf", "+Inf"); - ASSERT_TRUE (r0.varying_p ()); + if (r0.get_nan ().varying_p ()) + ASSERT_TRUE (r0.varying_p ()); // ...unless it has some special property... r0.set_nan (fp_prop::NO); ASSERT_FALSE (r0.varying_p ());