From patchwork Mon Oct 24 13:33:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 9131 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp456581wru; Mon, 24 Oct 2022 06:34:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7QsbpMLjiwDtOe1hbqnguZ3kZHosmGGUpMFvo1dHvq6fg8EMi1ID8nPNIZzlIvTPznYyf8 X-Received: by 2002:a05:6402:414f:b0:456:c2c1:23ec with SMTP id x15-20020a056402414f00b00456c2c123ecmr31522629eda.420.1666618466835; Mon, 24 Oct 2022 06:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618466; cv=none; d=google.com; s=arc-20160816; b=KL4wjwwXn0P8uejN3NTg9P3tQ3ZBotwCh89vh42z8m1NudI5bann/I19JVE1YTiXhR 92CaSGyGQBD3inSQKYsd2C5A0Zi6PHGuO1k+M99fUZgk7QDWbrfDL/iKh63Oux9xqc7O 4R+eBC1QrSvSinf4Cmhg7+VJl6gw6Lomwuwbg6QFsnzmQn2QaA1K/xkEdXWRl8h1vsaT DPJOaJ9NzL6JC5g1iYyscvquJO68KyAjQI8iLhn74jUFowqiplDhFxLDfttHXrwsx920 TK4+v1EhEt7I/Sn3wNtXr+c8C1q1n5AT3xMB3xK4B32WAZEEDG8afsnnZ4Nqu6qhPhTS IQ0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=BiP0VnpR4sVd19yHKRnvnG3I3U/tvpTp21MhI2Qrn2I=; b=BJpSRF4K7DGMCXLo3FG0TRvhl4reMf3f79jsXoNUPbH4gmpTfJi6l0LyI4E956Q2Md NkfRTezQGEaSWm3Qn0maN5/F9a5GiAMvZcFD7HqKlZg5kY6PCNWV87GhLNK/k/L0eFeJ J+kE9MWyHUwb5pZCht71opZL5V7sRTwcYOclVYusoz5dxR70LXlcErrqkGImrrlyO3b9 rDA70+D5p7wTTDvxnFZc6mawv2EVjhZbb7NpiexSG83aiwDgLnLUAUjE3w5Lj57vZ/gE aWjIrcJ7UmDiFLFZA9Zt+jSdNwb2oTEz0T7et2Cng/qO4LGMb4RJ6v0GiMgUvlDNb1VI Tf5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gByFk11Q; 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 sz15-20020a1709078b0f00b0078ddc074afdsi22049944ejc.577.2022.10.24.06.34.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 06:34:26 -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=gByFk11Q; 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 10A87385B839 for ; Mon, 24 Oct 2022 13:34:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10A87385B839 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666618460; bh=BiP0VnpR4sVd19yHKRnvnG3I3U/tvpTp21MhI2Qrn2I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=gByFk11Qm6sGzo5VfFrtkAJyTsdDd7MSRQyN+B208lN/F2tjYzqg+qPf7/yqGsyat bcxkkMNZZR5IQuYUjVY7C7xYzLpEAfQSKTg1YMKDn+GBjSTCIGgbDhWk+H+FNg+qPQ qf4OIJXOzGjBkRCiIUQOZ6JKaY6jSHT88U+iUUEo= 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 BD0BB3858412 for ; Mon, 24 Oct 2022 13:33:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BD0BB3858412 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-322-jVx9bilMM8-9adIiUd1DEQ-1; Mon, 24 Oct 2022 09:33:26 -0400 X-MC-Unique: jVx9bilMM8-9adIiUd1DEQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B271C8279A6 for ; Mon, 24 Oct 2022 13:33:25 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.194.177]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E9CE1121330; Mon, 24 Oct 2022 13:33: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 29ODXJtW033070 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 24 Oct 2022 15:33:19 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 29ODXJkZ033069; Mon, 24 Oct 2022 15:33:19 +0200 To: GCC patches Subject: [PATCH] [PR tree-optimization/107355] Handle NANs in abs range-op entry. Date: Mon, 24 Oct 2022 15:33:16 +0200 Message-Id: <20221024133316.33026-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 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, 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez 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?1747576125486190954?= X-GMAIL-MSGID: =?utf-8?q?1747576125486190954?= The problem here is that the threader is coming up with a path where the only valid result is a NAN. When the abs op1_range entry is trying to add the negative posibility, it attempts to get the bounds of the working range. NANs don't have bounds so they need to be special cased. PR tree-optimization/107355 gcc/ChangeLog: * range-op-float.cc (foperator_abs::op1_range): Handle NAN. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107355.c: New test. --- gcc/range-op-float.cc | 9 +++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr107355.c | 13 +++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107355.c diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 8777bc70d71..04208c88dd1 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -1269,6 +1269,15 @@ foperator_abs::op1_range (frange &r, tree type, positives.update_nan (/*sign=*/false); positives.intersect (lhs); r = positives; + // Add -NAN if relevant. + if (r.maybe_isnan ()) + { + frange neg_nan; + neg_nan.set_nan (type, true); + r.union_ (neg_nan); + } + if (r.known_isnan ()) + return true; // Then add the negative of each pair: // ABS(op1) = [5,20] would yield op1 => [-20,-5][5,20]. r.union_ (frange (type, diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107355.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107355.c new file mode 100644 index 00000000000..40796344bfb --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107355.c @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-O2 -fno-guess-branch-probability -fsanitize=float-cast-overflow --param=max-jump-thread-duplication-stmts=240" } + +float f; + +void +foo (double d) +{ + (char) f; + long l = __builtin_fabs (d); + (char) f; + (long) d; +}