From patchwork Sat Sep 17 07:39:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1276 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp100347wrt; Sat, 17 Sep 2022 00:40:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7VpUIrKMfh2MAsoa/pU1SLsn1cu7gucFbUhxBojmpBB9/yHraIhTvCc9uwrUC6GL4viHLe X-Received: by 2002:a05:6402:2949:b0:451:fabf:d88a with SMTP id ed9-20020a056402294900b00451fabfd88amr6837028edb.324.1663400427896; Sat, 17 Sep 2022 00:40:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663400427; cv=none; d=google.com; s=arc-20160816; b=rwXG2kdqVg8ORblwV1OkHb9IR0ICoIYuTEibRIdhlfrdM8s7M7wTc8SthIyMt5Jcav Lkg1/Hhc9zMHYLEurcIDE4vIUOaEh1KNxM/ZJCkNGHddwvkHzruhARbdhzQJAtCmw0DD n41D/UqzGX6aAI7OsagMjaZtrhj3tSoeGPBxMkVtFMCsgTrhu5NowxLfj0ktuYopg7eh EdCogHqlzmzQV5s4XcV4yUtyslitqC6005FgQc4rYbclZX4XPqIp7bhxHvvE5OVZKYA4 sTjVOkJmK6aWNgle/FCYr5fxKbAOtTY9nNHpOy8BPGtpvI3cHt8FH7ndwXx7+XHpwIlX IPHA== 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=KgYLF1EGiubQHsgSrRZMhduBhWJKht2zrJxel7ixrgo=; b=kiYiwSIH6itd0dEhAf91vhnjK++7xKVelEdmVbfjUUv718vr2vbXc7HRHxkFG7VNNP chztyXuJggoHV0QXSlvQay6Ccuzfs9DFNYRHdnVFcWD4AYoqaz+/PDhc3HKVsXAhsHQ9 E+JHc136yIMf9E6egkNfcuIPLXBgLjoMTfP1iwOWHPT17HHNjG1IcbCkqRM4zPOAPR19 kWDvGU39aO+D5gFhTF/82C/6rt8h8trMsmY9a8tGdRqgCAM1Ob2H9C9HFMle3m/cYWnK Ib7orZZpAS9M565RdXdksn2IFMGBRqfsSu6/RrXRg9efRskYcdbzfJv9IQ7JH6N4gOBg zxLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=n52GnASM; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hd34-20020a17090796a200b0077b9abe28f7si18665735ejc.739.2022.09.17.00.40.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 00:40:27 -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=n52GnASM; 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 830183AA9422 for ; Sat, 17 Sep 2022 07:40:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 830183AA9422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663400426; bh=KgYLF1EGiubQHsgSrRZMhduBhWJKht2zrJxel7ixrgo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=n52GnASMlUzBy0VyushI5/Vp2iP6CFyxO1KVeKtjQ3tayuOHoWDomlJse593O++pf 2czsPTmxfmSSWGtOltU6laqiI/LrJ0zPwdMHpyzhkWjt4pqadMi2eJ6UYLzMTWdq8l SkyH+wSV2m7Gtx5nEsrx9hZX+6ukTWDo/eISGStc= 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 364F63AA9410 for ; Sat, 17 Sep 2022 07:39:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 364F63AA9410 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-629-572WV3X-P--5QCBODnmL6g-1; Sat, 17 Sep 2022 03:39:36 -0400 X-MC-Unique: 572WV3X-P--5QCBODnmL6g-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 775D43C0218C; Sat, 17 Sep 2022 07:39:36 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.11]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 148B649BB60; Sat, 17 Sep 2022 07:39:35 +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 28H7dYBk1542849 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 17 Sep 2022 09:39:34 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 28H7dX3X1542848; Sat, 17 Sep 2022 09:39:33 +0200 To: Jakub Jelinek Subject: [PATCH] [PR106831] Avoid propagating long doubles that may have multiple representations. Date: Sat, 17 Sep 2022 09:39:26 +0200 Message-Id: <20220917073926.1542752-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=-12.3 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 , Joseph Myers 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?1744201766994580381?= X-GMAIL-MSGID: =?utf-8?q?1744201766994580381?= Long doubles are tricky when it comes to considering singletons because small numbers and +-INF can have multiple representations for the same number. So we need to be very careful not to treat those as singletons, lest they be incorrectly propagated by VRP. This is similar to the -0.0 and +0.0 duality. In long doubles +INF can be represented with +INF in the MSB and either -0.0 or +0.0 in the LSB. Similarly for numbers that are exactly representable in DF. For example, 1.0 can be represented as either (1.0, +0.0) or (1.0, -0.0). This patch avoids treating these numbers as singletons. Note that NANs in long double format have a LSB of don't care, but this is irrelevant for singleton_p, because NANs are never considered singletons. Also, internally in the frange we store NANs as a pair of boolean flags indicating whether they are +NAN or -NAN, so we don't need any special treatment here for comparing range equality etc. We never see anything but the boolean flags. (Errr, the boolean flags are not yet in trunk, but should go in shortly). I will push this patch after tests complete. Thank you Jakub for providing this patch. PR middle-end/106831 gcc/ChangeLog: * value-range.cc (frange::singleton_p): Avoid propagating long doubles that may have multiple representations. --- gcc/value-range.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 55a216efd8b..67d5d7fa90f 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -639,6 +639,21 @@ frange::singleton_p (tree *result) const if (HONOR_NANS (m_type) && maybe_isnan ()) return false; + if (MODE_COMPOSITE_P (TYPE_MODE (m_type))) + { + // For IBM long doubles, if the value is +-Inf or is exactly + // representable in double, the other double could be +0.0 + // or -0.0. Since this means there is more than one way to + // represent a value, return false to avoid propagating it. + // See libgcc/config/rs6000/ibm-ldouble-format for details. + if (real_isinf (&m_min)) + return false; + REAL_VALUE_TYPE r; + real_convert (&r, DFmode, &m_min); + if (real_identical (&r, &m_min)) + return false; + } + if (result) *result = build_real (m_type, m_min); return true;