From patchwork Sun Jan 15 10:32:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 43825 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp678468wrn; Sun, 15 Jan 2023 02:33:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXvPFtnKgCrTaaQY967QXdFq1LyFFTULM0Nb1IdN4pSei+WDc3Cz3ygMh2wJVyo01cgLV8+h X-Received: by 2002:a05:6402:2488:b0:46b:34a:3945 with SMTP id q8-20020a056402248800b0046b034a3945mr89372562eda.31.1673778804590; Sun, 15 Jan 2023 02:33:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673778804; cv=none; d=google.com; s=arc-20160816; b=vqQJE5Ouw3YvKVrV8rVNvdofFD4KWuWiq6iMg9awYrhy1CMKIMNTUs4Zx6r+Vz1l+t WYCTKyum85ajXG0GIrBH1eEbMz5AXOqq7NuUdUxAJNI51xGnAkdwXs9ppKM+9u8keSEu 1rlZUcbgaw7+YWBvlpm8UHyY48zMNdMFW78Tn79URuoiZvvhv2c4LMzdc6dylBymzj1y pdO8dsZ7+55UtnM1CCeNYQ9Sl5zqGjHzQMxgY5Chypz4RKtqTD01DECN3AmCENnDGB4m 0UAG9E9GHglFyNkF87j4lscWiPYcUoeNzB6ZFLVqLfHV9/rlvtHzruh5vZXTgRce4pCl /1DA== 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:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=pfI1fv5ChpiJNeprbOBkk9y8zFbID+euKv4AwnW6ct0=; b=Y+Ot0aoDZ8+PQEdehuKqtuZEAoRxj+GfZaNmE/DkrMLJs5U3bzJjsGnjWaYVGzDdnT MvMklB/KgOcDBb/9ppdOx3NGtRWpuVQEhXJKUj7Ih5vB9PBdIRRArtN8kWsmdBVys1OS ky79+UoWe6C4BpAH9ZG/hSn96riyqPe+jPh4wTlLjj4Zy4LJPNu4Sb0/AEBYBHk/QH4h 2WzahcGfD2R4AZyOl+Gy1IozvN9M0YUtbaRH5YjL+V/slJg3ApeS2W0jnoZo9ecBijED f1mzP9NIYrv3UraTL3keUIbn3b6n/H23D30UbMnLgZSYyuw+81MxUYlInqP11ZkbBF0H KFgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XmP3o5cq; 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 xa11-20020a170906fd8b00b0078d9f02b452si27896960ejb.861.2023.01.15.02.33.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Jan 2023 02:33:24 -0800 (PST) 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=XmP3o5cq; 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 B526B38582A4 for ; Sun, 15 Jan 2023 10:33:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B526B38582A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673778800; bh=pfI1fv5ChpiJNeprbOBkk9y8zFbID+euKv4AwnW6ct0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=XmP3o5cq0t4SQCH8I4BfKTwlInHvrFV+GeqcwuPQIgYC7yntj4njirVWztG7uosku A+w6Gayv1Rj9OCZUMxTbGzZ11GO0xlFYwxHDDTQ0vzi6MRZQvfP0NSISfdMdTpZyCK XatRIQr2YnNrwZAspvI8HUr9fTpGuNB+kVunc2Qc= 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 59CC93858D32 for ; Sun, 15 Jan 2023 10:32:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 59CC93858D32 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-591-5lRojOANM_WX9xQZQPvXxw-1; Sun, 15 Jan 2023 05:32:34 -0500 X-MC-Unique: 5lRojOANM_WX9xQZQPvXxw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA4073802B88; Sun, 15 Jan 2023 10:32:33 +0000 (UTC) Received: from abulafia.quesejoda.com (ovpn-192-35.brq.redhat.com [10.40.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5241340C2064; Sun, 15 Jan 2023 10:32:33 +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 30FAWUah019426 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 15 Jan 2023 11:32:30 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 30FAWUkV019425; Sun, 15 Jan 2023 11:32:30 +0100 To: Jakub Jelinek Cc: Richard Biener , Andrew MacLeod , GCC patches , Aldy Hernandez Subject: [PATCH] [PR107608] [range-ops] Avoid folding into INF when flag_trapping_math. Date: Sun, 15 Jan 2023 11:32:27 +0100 Message-Id: <20230115103227.19393-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 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?1755083983197175447?= X-GMAIL-MSGID: =?utf-8?q?1755084283915036307?= As discussed in the PR, for trapping math, do not fold overflowing operations into +-INF as doing so could elide a trap. There is a minor adjustment to known_isinf() where it was mistakenly returning true for an [infinity U NAN], whereas it should only return true when the range is exclusively +INF or -INF. This is benign, as there were no users of known_isinf up to now. I had some testsuite issues with: > FAIL: c-c++-common/diagnostic-format-sarif-file-4.c -std=gnu++14 scan-sarif-file "text": " int \\\\u6587\\\\u5b57\\\\u5316\\\\u3051 = > FAIL: c-c++-common/diagnostic-format-sarif-file-4.c -std=gnu++17 scan-sarif-file "text": " int \\\\u6587\\\\u5b57\\\\u5316\\\\u3051 = > FAIL: c-c++-common/diagnostic-format-sarif-file-4.c -std=gnu++20 scan-sarif-file "text": " int \\\\u6587\\\\u5b57\\\\u5316\\\\u3051 = > FAIL: c-c++-common/diagnostic-format-sarif-file-4.c -std=gnu++98 scan-sarif-file "text": " int \\\\u6587\\\\u5b57\\\\u5316\\\\u3051 = > FAIL: g++.dg/pr71488.C (test for excess errors) > FAIL: g++.dg/guality/pr55665.C -O2 -flto -fno-use-linker-plugin -flto-partition=none line 23 p == 40 > FAIL: c-c++-common/diagnostic-format-sarif-file-4.c -Wc++-compat scan-sarif-file "text": " int \\\\u6587\\\\u5b57\\\\u5316\\\\u3051 = < FAIL: g++.dg/pr71488.C (test for excess errors) < FAIL: g++.dg/guality/pr55665.C -O2 -flto -fno-use-linker-plugin -flto-partition=none line 23 p == 40 > FAIL: ./index0-out.go execution, -O0 -g -fno-var-tracking-assignments > FAIL: go.test/test/fixedbugs/issue27836.dir/Äfoo.go -O -I. (test for excess errors) > FAIL: go.test/test/fixedbugs/issue27836.dir/Ämain.go -O -I. (test for excess errors) But they seem to be transient issues on my machine, as re-running them manually don't cause any issues. Also, the tests themselves have nothing to do with floats so I don't see how they could be related. Tested on x86-64 Linux. I also ran the glibc testsuite (git sources) on x86-64 and this patch fixes: -FAIL: math/test-double-lgamma -FAIL: math/test-double-log1p -FAIL: math/test-float-lgamma -FAIL: math/test-float-log1p -FAIL: math/test-float128-catan -FAIL: math/test-float128-catanh -FAIL: math/test-float128-lgamma -FAIL: math/test-float128-log -FAIL: math/test-float128-log1p -FAIL: math/test-float128-y0 -FAIL: math/test-float128-y1 -FAIL: math/test-float32-lgamma -FAIL: math/test-float32-log1p -FAIL: math/test-float32x-lgamma -FAIL: math/test-float32x-log1p -FAIL: math/test-float64-lgamma -FAIL: math/test-float64-log1p -FAIL: math/test-float64x-lgamma -FAIL: math/test-ldouble-lgamma OK for trunk? PR tree-optimization/107608 gcc/ChangeLog: * range-op-float.cc (range_operator_float::fold_range): Avoid folding into INF when flag_trapping_math. * value-range.h (frange::known_isinf): Return false for possible NANs. --- gcc/range-op-float.cc | 21 +++++++++++++++++++++ gcc/value-range.h | 1 + 2 files changed, 22 insertions(+) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 986a3896a4f..74ac4658378 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -91,6 +91,27 @@ range_operator_float::fold_range (frange &r, tree type, else r.clear_nan (); + // If the result has overflowed and flag_trapping_math, folding this + // operation could elide an overflow or division by zero exception. + // Avoid returning a singleton +-INF, to keep the propagators (DOM + // and substitute_and_fold_engine) from folding. See PR107608. + if (flag_trapping_math + && MODE_HAS_INFINITIES (TYPE_MODE (type)) + && r.known_isinf () && !op1.known_isinf () && !op2.known_isinf ()) + { + REAL_VALUE_TYPE inf = r.lower_bound (); + if (real_isneg (&inf)) + { + REAL_VALUE_TYPE min = real_min_representable (type); + r.set (type, inf, min); + } + else + { + REAL_VALUE_TYPE max = real_max_representable (type); + r.set (type, max, inf); + } + } + return true; } diff --git a/gcc/value-range.h b/gcc/value-range.h index ea50ed3e64a..f4ac73b499f 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -1300,6 +1300,7 @@ inline bool frange::known_isinf () const { return (m_kind == VR_RANGE + && !maybe_isnan () && real_identical (&m_min, &m_max) && real_isinf (&m_min)); }