From patchwork Sat Sep 17 08:24:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp112634wrt; Sat, 17 Sep 2022 01:25:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6JIxNYOVzj7hnf15Ib5dv3ukv7SrDiQ06g9m1cijdgvJIwkj8+FqFNBBoJ/uR+T9jOeS3h X-Received: by 2002:aa7:cb83:0:b0:443:3f15:84fe with SMTP id r3-20020aa7cb83000000b004433f1584femr7215925edt.17.1663403128737; Sat, 17 Sep 2022 01:25:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663403128; cv=none; d=google.com; s=arc-20160816; b=NL/VR4Nxo3pw2X+0wMrgzMhxVCDGFIA1LuAhzHoOe0p6lt4aoYB3zXNw0dEA6YKY5g tOcYEz1GuxEuhTmuOgXXSUjd9uL5RQbrocqQ8XtkfqPp5vv19QoA+vP2TercqUUp44XX uZjhvJb4Ju/+a7u/IRIXsuCgJn7LteQYn90pVAMfMQyiN7RmhYfY7Jqng52GT1nq2E1H 9D84MnFCzgLvlYaINd8tIjlUoxFg5+o2IosJ4k6VHPDi/KLxanOgTTgoNbEK3eQLzQ0J 9KkIebEWX1SRoykYB4zHxa5TT5j1yFY5TjL/1nxjDm9YkugIURv4NAIJdv4ZVCsi6BPv J+Bg== 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=p/YxWrLRTx7kRMCbeW+npAOoYKbpcJ7eGs9cFktgEYo=; b=Jtv+yDe0XGbNr+GFNso2HPdJ4bkuQL8C5ofQIvQ3bm+coRSLqdYfKrMs78Pkcr2KOI vBCZjhc2ulKhdGnhpbkHtiJ+HxJ+0FEJvaM1FP1ny+6vUDLyzUfaF11Whsbj+z1ZS6yW h1o95f+SPl9qs4kl1O8RUkpVZ2SAIDuchm9lyzy6ol117n+9pZmWTfgyB6yUlGvSqklO 5n7GIY4dEQY4ZJEWp8K6YoNbf1eOClYyGAX3ui9uWn7hpNdvpbbB/XoiN/xcYRwQk6zX mOTmsYRLJ7nWUQTirGRzwk5aNzeDkHGGjbTFPe8mVQlwl9RyweUlZ7fd2uLO/XVMxLHN 758w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DUrMMvqW; 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 d9-20020a170906304900b007417c184ea5si17691528ejd.628.2022.09.17.01.25.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 01:25:28 -0700 (PDT) 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=DUrMMvqW; 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 C80AF38328EB for ; Sat, 17 Sep 2022 08:25:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C80AF38328EB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663403107; bh=p/YxWrLRTx7kRMCbeW+npAOoYKbpcJ7eGs9cFktgEYo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=DUrMMvqWolECiUtapfNNAGulJMEfDy6Vt7Mp9BZ/0UDKCBMXvLs5VQH9QRVWXSLK1 MWWCZ63Eg6ZbbP1MRfdHj50T9oJVAq/b7LpZCug9FXgWmq6LpUusx+kE4SbzIJNNGB meBWtTujmgixCj0PFysFbZKzKfSQOLpVzt0iHXMA= 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 5D901383177E for ; Sat, 17 Sep 2022 08:24:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5D901383177E 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-135-lEKGaKPBOvuL1R81MSGOPQ-1; Sat, 17 Sep 2022 04:24:18 -0400 X-MC-Unique: lEKGaKPBOvuL1R81MSGOPQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 37DCA185A78F; Sat, 17 Sep 2022 08:24:18 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.11]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C557C492CA2; Sat, 17 Sep 2022 08:24:17 +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 28H8OFRA1573751 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 17 Sep 2022 10:24:15 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 28H8OFdW1573750; Sat, 17 Sep 2022 10:24:15 +0200 To: Jakub Jelinek , Richard Henderson Subject: [PATCH] frange: flush denormals to zero for -funsafe-math-optimizations. Date: Sat, 17 Sep 2022 10:24:03 +0200 Message-Id: <20220917082403.1573721-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 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_LOW, 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Cc: GCC patches 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?1744204599104227253?= X-GMAIL-MSGID: =?utf-8?q?1744204599104227253?= Jakub has mentioned that for -funsafe-math-optimizations we may flush denormals to zero, in which case we need to be careful to extend the ranges to the appropriate zero. This patch does exactly that. For a range of [x, -DENORMAL] we flush to [x, -0.0] and for [+DENORMAL, x] we flush to [+0.0, x]. It is unclear whether we should do this for Alpha, since I believe flushing to zero is the default, and the port requires -mieee for IEEE sanity. If so, perhaps we should add a target hook so backends are free to request flushing to zero. Thoughts? gcc/ChangeLog: * value-range.cc (frange::flush_denormals_to_zero): New. (frange::set): Call flush_denormals_to_zero. * value-range.h (class frange): Add flush_denormals_to_zero. --- gcc/value-range.cc | 24 ++++++++++++++++++++++++ gcc/value-range.h | 1 + 2 files changed, 25 insertions(+) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 67d5d7fa90f..f285734f0e0 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -267,6 +267,26 @@ tree_compare (tree_code code, tree op1, tree op2) return !integer_zerop (fold_build2 (code, integer_type_node, op1, op2)); } +// Flush denormal endpoints to the appropriate 0.0. + +void +frange::flush_denormals_to_zero () +{ + if (undefined_p () || known_isnan ()) + return; + + // Flush [x, -DENORMAL] to [x, -0.0]. + if (real_isdenormal (&m_max) && real_isneg (&m_max)) + { + m_max = dconst0; + if (HONOR_SIGNED_ZEROS (m_type)) + m_max.sign = 1; + } + // Flush [+DENORMAL, x] to [+0.0, x]. + if (real_isdenormal (&m_min) && !real_isneg (&m_min)) + m_min = dconst0; +} + // Setter for franges. void @@ -317,6 +337,10 @@ frange::set (tree min, tree max, value_range_kind kind) gcc_checking_assert (tree_compare (LE_EXPR, min, max)); normalize_kind (); + + if (flag_unsafe_math_optimizations) + flush_denormals_to_zero (); + if (flag_checking) verify_range (); } diff --git a/gcc/value-range.h b/gcc/value-range.h index 3a401f3e4e2..795b1f00fdc 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -327,6 +327,7 @@ private: bool union_nans (const frange &); bool intersect_nans (const frange &); bool combine_zeros (const frange &, bool union_p); + void flush_denormals_to_zero (); tree m_type; REAL_VALUE_TYPE m_min;