From patchwork Tue Apr 11 08:21:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 81798 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2411357vqo; Tue, 11 Apr 2023 01:22:52 -0700 (PDT) X-Google-Smtp-Source: AKy350bQWW2o5c6g52YSljMfTts8pcl3C04ndqdIxjKZ6zCNAfKQAGifuWehWcBhkGBhpzSGRvGW X-Received: by 2002:a17:907:60c6:b0:932:10bf:ec4d with SMTP id hv6-20020a17090760c600b0093210bfec4dmr9013579ejc.25.1681201372644; Tue, 11 Apr 2023 01:22:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681201372; cv=none; d=google.com; s=arc-20160816; b=Fd1Fzcyg5Lugsvgu+egNGh7nJC8vC1C97OW6DJk/xkx0XsB8GUfiz+QyK6Z9kOFDMo nrP3ZgtuwFLzvCEqw+5JNvMTtrU0lm1lJn3qoo0TgqpLh0jSoe/9HGiSC78LV0ZUfQId O2W91l7HXuUFwt1kNgKTKtbalXZ3aW+d4E4tafDSGizi/+Mm6gTo/tR/MForpSZ8AqRd Mb8vRNFEVDY0o/YBPnU6sxb+5QCi7/2DIXnngL6jWj3apYlDkB2i3mRYv46+9iJE+r6M ir5+G37h8ns/f02owD5OyDvnzQzGM80NX8WWXN3pTeB0KjKwA1JgGZe4wKhOi94LBXZP 0C5g== 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-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Y2RJgqqujGc6Ux8ihx+yY8RF2Ot1lHLIWPhELxwzQSM=; b=Hf1hb3Lt0y/gauIz7RZ8rYE0K4BQFQiz5RoDM2jD6Ch7LHvi9USHjx/ILZ/vlVrGxt xGQChwjxBwZXY9qcokFIpNUVVDRDyg5ePSfWxL4Chn7NvTk39t9p6TEFsTMb+lXsOWYX 9AH+QNND3baRS06CrUSLycnvD0pWSaawig0zk5ESZea07XOZx96d6sg+hAKpy6v3ZH/K X0fezAYFFC0hyl0pLlDoMYxB7TyzStJ0o2eqiKjymo+BDmOBH/LxuxDiumT5x+YKIV4G wKX3N4s1ifce1OhqfLf836XqQY7hNyxUKG/EwwINbhvXtM/4OLdxhupCB42uIKTYHt7N gY7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aVA4VTQP; 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 gn27-20020a1709070d1b00b0093e0b659bc3si2719965ejc.493.2023.04.11.01.22.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 01:22:52 -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=aVA4VTQP; 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 76809385802F for ; Tue, 11 Apr 2023 08:22:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76809385802F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681201371; bh=Y2RJgqqujGc6Ux8ihx+yY8RF2Ot1lHLIWPhELxwzQSM=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=aVA4VTQP1hTI38WVj1tLjPB4ihZreLxEnFpgyWg+Gxnnl9uC7UxaHcZ+aq45hjq1E m72c1TVBLQ/ujUvMp87YMk6fqEoZu+tIREjzYq+18fr1f9ExnYSX6IOGZ4AGB20cLq rcDFJo1Ua0ZpZkj56f+q7K+PQHhq/WFyvB0+1il0= 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 0384E3857BB2 for ; Tue, 11 Apr 2023 08:22:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0384E3857BB2 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-169-iyiMBR9NP_SSQ-ZmZTGJkQ-1; Tue, 11 Apr 2023 04:22:01 -0400 X-MC-Unique: iyiMBR9NP_SSQ-ZmZTGJkQ-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 43ADF8996EA for ; Tue, 11 Apr 2023 08:22:01 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F0A9C1121320; Tue, 11 Apr 2023 08:22:00 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 33B8LwBq2465786 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 11 Apr 2023 10:21:58 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 33B8Lvbo2465785; Tue, 11 Apr 2023 10:21:57 +0200 Date: Tue, 11 Apr 2023 10:21:57 +0200 To: Aldy Hernandez , Andrew MacLeod Cc: gcc-patches@gcc.gnu.org Subject: [RFC PATCH] range-op-float: Fix up op1_op2_relation of comparisons Message-ID: 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 Content-Disposition: inline X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: 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?1762867410432632599?= X-GMAIL-MSGID: =?utf-8?q?1762867410432632599?= Hi! This patch was what I've tried first before the currently committed PR109386 fix. Still, I think it is the right thing until we have proper full set of VREL_* relations for NANs (though it would be really nice if op1_op2_relation could be passed either type of the comparison operands, or even better ranges of the two operands, such that we could choose if inversion of say VREL_LT is VREL_GE (if !MODE_HONOR_NANS (TYPE_MODE (type))) or rhs1/rhs2 ranges are guaranteed not to include NANs (!known_isnan && !maybe_isnan for both), or VREL_UNGE, etc. Anyway, the current state is that for the LE/LT/GE/GT comparisons we pretend the inverse is like for integral comparisons, which is true only if NANs can't appear in operands, while for UNLE/UNLT/UNGE/UNGT we don't override op1_op2_relation (so it always yields VREL_VARYING). Though, this patch regresses the FAIL: gcc.dg/tree-ssa/vrp-float-6.c scan-tree-dump-times evrp "Folding predicate x_.* <= y_.* to 1" 1 test, so am not sure what to do with it. The test has explicit !isnan tests around it, so e.g. having the ranges passed to op1_op2_relation would also fix it. 2023-04-11 Jakub Jelinek * range-op-float.cc (foperator_lt::op1_op2_relation): Return VREL_VARYING instead of VREL_GE. (foperator_le::op1_op2_relation): Return VREL_VARYING instead of VREL_GT. (foperator_gt::op1_op2_relation): Return VREL_VARYING instead of VREL_LE. (foperator_ge::op1_op2_relation): Return VREL_VARYING instead of VREL_LT. (foperator_unordered_lt::op1_op2_relation, foperator_unordered_le::op1_op2_relation, foperator_unordered_gt::op1_op2_relation, foperator_unordered_ge::op1_op2_relation): New. Jakub --- gcc/range-op-float.cc.jj 2023-04-01 09:32:02.635423345 +0200 +++ gcc/range-op-float.cc 2023-04-03 10:42:54.000000000 +0200 @@ -831,7 +831,10 @@ public: relation_trio = TRIO_VARYING) const final override; relation_kind op1_op2_relation (const irange &lhs) const final override { - return lt_op1_op2_relation (lhs); + relation_kind ret = lt_op1_op2_relation (lhs); + if (ret == VREL_GE) + ret = VREL_VARYING; // Inverse of VREL_LT is VREL_UNGE. + return ret; } bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, @@ -947,6 +950,10 @@ public: relation_trio rel = TRIO_VARYING) const final override; relation_kind op1_op2_relation (const irange &lhs) const final override { + relation_kind ret = le_op1_op2_relation (lhs); + if (ret == VREL_GT) + ret = VREL_VARYING; // Inverse of VREL_LE is VREL_UNGT. + return ret; return le_op1_op2_relation (lhs); } bool op1_range (frange &r, tree type, @@ -1057,7 +1064,10 @@ public: relation_trio = TRIO_VARYING) const final override; relation_kind op1_op2_relation (const irange &lhs) const final override { - return gt_op1_op2_relation (lhs); + relation_kind ret = gt_op1_op2_relation (lhs); + if (ret == VREL_LE) + ret = VREL_VARYING; // Inverse of VREL_GT is VREL_UNLE. + return ret; } bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, @@ -1177,7 +1187,10 @@ public: relation_trio = TRIO_VARYING) const final override; relation_kind op1_op2_relation (const irange &lhs) const final override { - return ge_op1_op2_relation (lhs); + relation_kind ret = ge_op1_op2_relation (lhs); + if (ret == VREL_LT) + ret = VREL_VARYING; // Inverse of VREL_GE is VREL_UNLT. + return ret; } bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, @@ -1571,6 +1584,7 @@ class foperator_unordered_lt : public ra using range_operator_float::fold_range; using range_operator_float::op1_range; using range_operator_float::op2_range; + using range_operator_float::op1_op2_relation; public: bool fold_range (irange &r, tree type, const frange &op1, const frange &op2, @@ -1599,6 +1613,13 @@ public: return true; } } + relation_kind op1_op2_relation (const irange &lhs) const final override + { + relation_kind ret = lt_op1_op2_relation (lhs); + if (ret == VREL_LT) + ret = VREL_VARYING; // Should have been VREL_UNLT. + return ret; + } bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, @@ -1682,6 +1703,7 @@ class foperator_unordered_le : public ra using range_operator_float::fold_range; using range_operator_float::op1_range; using range_operator_float::op2_range; + using range_operator_float::op1_op2_relation; public: bool fold_range (irange &r, tree type, const frange &op1, const frange &op2, @@ -1710,6 +1732,13 @@ public: return true; } } + relation_kind op1_op2_relation (const irange &lhs) const final override + { + relation_kind ret = le_op1_op2_relation (lhs); + if (ret == VREL_LE) + ret = VREL_VARYING; // Should have been VREL_UNLE. + return ret; + } bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, relation_trio = TRIO_VARYING) const final override; @@ -1789,6 +1818,7 @@ class foperator_unordered_gt : public ra using range_operator_float::fold_range; using range_operator_float::op1_range; using range_operator_float::op2_range; + using range_operator_float::op1_op2_relation; public: bool fold_range (irange &r, tree type, const frange &op1, const frange &op2, @@ -1817,6 +1847,13 @@ public: return true; } } + relation_kind op1_op2_relation (const irange &lhs) const final override + { + relation_kind ret = gt_op1_op2_relation (lhs); + if (ret == VREL_GT) + ret = VREL_VARYING; // Should have been VREL_UNGT. + return ret; + } bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, relation_trio = TRIO_VARYING) const final override; @@ -1900,6 +1937,7 @@ class foperator_unordered_ge : public ra using range_operator_float::fold_range; using range_operator_float::op1_range; using range_operator_float::op2_range; + using range_operator_float::op1_op2_relation; public: bool fold_range (irange &r, tree type, const frange &op1, const frange &op2, @@ -1928,6 +1966,13 @@ public: return true; } } + relation_kind op1_op2_relation (const irange &lhs) const final override + { + relation_kind ret = ge_op1_op2_relation (lhs); + if (ret == VREL_GE) + ret = VREL_VARYING; // Should have been VREL_UNGE. + return ret; + } bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, relation_trio = TRIO_VARYING) const final override;