From patchwork Mon Jan 23 17:44:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 47269 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1733868wrn; Mon, 23 Jan 2023 09:45:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXter9Zsmlo8KQToD9ohp3o8kpdVGWxw+e35gU5Wl+jIzp3nFP+/Qvjqvb7ZyWqVfsNVY9a4 X-Received: by 2002:a17:907:2106:b0:7c1:32:3574 with SMTP id qn6-20020a170907210600b007c100323574mr29491488ejb.12.1674495959262; Mon, 23 Jan 2023 09:45:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674495959; cv=none; d=google.com; s=arc-20160816; b=meShNV9o4oXrbeClg+JJlZjkl4xsDRZ1QSTpy7rPFp7Zqbu2HVF9xSW1KzN4jc2phn giNVf/Wg0bK05FClB5oBruox5JI1ZXJTH14567Et9tUyz+SmBqI/Jn/pVZeG0wZnrjoS +fbQUY1pB3jNQ4iwyxjCAOWfwOAsIXEn+/CwMHWPMsgf0SWkSCD72rAJBC5orQTHlwS0 I7lxajwl901SnAO0AcoE7bPvgqXDlltgfRzPgq2Qg2tZbutiWnTdUrBooFFguhEmHXa+ JyCBtCa9BqsVXGODbese0sIDCe6s3Af8njbKIHmY9FiI4K+qhWfgXr9lcbswhYVEd16v M8RQ== 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-language :subject:cc:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=ZhfFqBcDFsWValA4v7NuWxRJMYHy/UciHiA8NSFLKFU=; b=yrrMS17WKcKHFOQBH5J2tSZpe/uYsPRbVQHPhgVMo660lPo8HJi/SdIapjvlYQUJSL ZYF4I4Bqdr+FWnhiyv8kwXRM/hCmyVc4TB9W3kjrws3KZVtAZ077Yq6AOFfb6XW+BMQd r6SG0S1H3TfRyVq7wEiKuA+JBzV/xkz4ZJ5QOvUYn8d7rZ+RnN8cAxHHFmh7hS7fVhK9 Vkfw1MVuoF7DOURpn2I+/OJD/cLdMsYNnxiScgdqAJ4hpyIW584CAjdDChkt+ZeUr/Vd kee4GMDY/48F6paG/gSaHeF00PzxmEQPuH9aa8SHn8sdxAiWgbvPA/diBDCJw46kPg79 OYpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gxAc7mlv; 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 gb7-20020a170907960700b008705caf2257si28747949ejc.513.2023.01.23.09.45.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 09:45:59 -0800 (PST) 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=gxAc7mlv; 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 5DCD03857007 for ; Mon, 23 Jan 2023 17:45:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DCD03857007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674495935; bh=ZhfFqBcDFsWValA4v7NuWxRJMYHy/UciHiA8NSFLKFU=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=gxAc7mlvOsCaBg5fXuwFK+5SrgKm7BRtkxVbXBw4+oMFf4+ES1gPmBbOkUnOir3vg MdhFFerdLH9TVa+2orhbFhNX1oLST12KIi5dNK5eKsozXyHdf11iVW/sKPJrqmt2yY cOarmfbuXklgmSnbJqPE6uen+p1DhwcoB12StG6w= 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 7FB7C3858D32 for ; Mon, 23 Jan 2023 17:44:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7FB7C3858D32 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-94-x1wYhwgnOGmLUle3hktDhw-1; Mon, 23 Jan 2023 12:44:47 -0500 X-MC-Unique: x1wYhwgnOGmLUle3hktDhw-1 Received: by mail-qk1-f199.google.com with SMTP id az16-20020a05620a171000b00709129a745eso6973406qkb.8 for ; Mon, 23 Jan 2023 09:44:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hTzNRz1vzPjueGOw88N4cv6u0DmFwjmztIEbyVusoj4=; b=PB7f0p78u6PUNL0YYGn6ASkZhP+tX4KN5PdrXjaonpEH3leiIagpMI050mOTKfTEiu tj6nYlZij56fURshzAkAoQZg6GSQd5lOhsRdhm3VkWGtLrXXT5I0icAkUFZCfjyxzCLZ lrMQrYm7T3UKOlBRLKBDObPl4czle94MgwzZbY70TTpYfdwEerApL+PafMjZBgxyziBZ 1Ri7r19uT3zplNS5Yqb4UISrogvfNowyAs+W1DVV/XHUi7aNLSa/DU9eB+FfxZTgBjRS lnmw3iUh6orGNbeev8wbmVWB4rxsqG9i4UGdBjt5CmuWMdmnGKZoai3+S7HNYNKxPI8p ARAg== X-Gm-Message-State: AFqh2krDKGNyDN/AqAufam48rTB4QzCjjPdd4EikbWLZiQR4XWLa5UTN 2S51KOFslUim2sOlKKPAZumWDATXGejF/MXqqE/smHZn/VkRdVjb7k8R6voxF6zG1SePUm9msmv FDVrxsqhkpoSj3xWcUn6E7vX6mtvuJbCLHxUHarbaegUsnuPOZXjnQYU1Bu0zKEPHjABUIA== X-Received: by 2002:ac8:7a8b:0:b0:3b6:2b50:15eb with SMTP id x11-20020ac87a8b000000b003b62b5015ebmr46282622qtr.57.1674495884982; Mon, 23 Jan 2023 09:44:44 -0800 (PST) X-Received: by 2002:ac8:7a8b:0:b0:3b6:2b50:15eb with SMTP id x11-20020ac87a8b000000b003b62b5015ebmr46282596qtr.57.1674495884648; Mon, 23 Jan 2023 09:44:44 -0800 (PST) Received: from ?IPV6:2607:fea8:a263:f600::27bf? ([2607:fea8:a263:f600::27bf]) by smtp.gmail.com with ESMTPSA id az20-20020a05620a171400b007091068cff1sm7411980qkb.28.2023.01.23.09.44.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Jan 2023 09:44:44 -0800 (PST) Message-ID: <2b7a5b75-aa71-b399-ff07-1f62dfac6cdc@redhat.com> Date: Mon, 23 Jan 2023 12:44:42 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 To: gcc-patches Cc: "hernandez, aldy" , Jakub Jelinek , Richard Biener Subject: [PATCH 1/2] Use value_relation class instead of direct calls to intersect/union. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.9 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod 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?1755836275216146291?= X-GMAIL-MSGID: =?utf-8?q?1755836275216146291?= In order to fix 108447, this patch changes the calls to relation_union and relation_intersection to instead utilize the value_relation class, and make the calls through that instead. value_relation manages the operands of a relation, and thus understands whether this is a floating point relation and can make any adjustments required to get the proper results.  THis patch doesn't do anything additional, just that isolation so we can track if it introduces anything speerate from the next change which adds another relation. Bootstraps on x86_64-pc-linux-gnu with no regressions.  OK? Andrew From 566421cb3b91272b56b01ff9ad5a243cada38ff7 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Fri, 20 Jan 2023 17:13:08 -0500 Subject: [PATCH 1/2] Use value_relation class instead of direct calls to intersect/union. There are subtle differences how union and intersection behave depending on whetehr the operands are float or integral. Directly calling relation_union or relation_intersect does not expose the origin of the operands, but value_relation does have them. THis patch makes sure calls are through the value relation class. * gimple-range-fold.cc (fold_using_range::relation_fold_and_or): Call union and intersect through a value_relation class. * value-relation.cc (value_relation::intersect): Make parameter const. (value_relation::union_): Likewise. (dom_oracle::set_one_relation): Use value-relation class for union and intersect. (path_oracle::register_relation): Likewise. * value-relation.h (value_relation::intersect): Add const to param. (value_relation::union_): Likewise. --- gcc/gimple-range-fold.cc | 17 +++++------------ gcc/value-relation.cc | 17 ++++++++--------- gcc/value-relation.h | 4 ++-- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 91eb6298254..500c482eeec 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -1039,14 +1039,6 @@ fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s, if (!ssa1_dep1 || !ssa1_dep2 || !ssa2_dep1 || !ssa2_dep2) return; - // Make sure they are the same dependencies, and detect the order of the - // relationship. - bool reverse_op2 = true; - if (ssa1_dep1 == ssa2_dep1 && ssa1_dep2 == ssa2_dep2) - reverse_op2 = false; - else if (ssa1_dep1 != ssa2_dep2 || ssa1_dep2 != ssa2_dep1) - return; - int_range<2> bool_one (boolean_true_node, boolean_true_node); relation_kind relation1 = handler1.op1_op2_relation (bool_one); @@ -1054,15 +1046,16 @@ fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s, if (relation1 == VREL_VARYING || relation2 == VREL_VARYING) return; - if (reverse_op2) - relation2 = relation_negate (relation2); + value_relation vr1 (relation1, ssa1_dep1, ssa1_dep2); + value_relation vr2 (relation2, ssa2_dep1, ssa2_dep2); + // Only one of the follwoing intersection/unions is performed. // x && y is false if the relation intersection of the true cases is NULL. - if (is_and && relation_intersect (relation1, relation2) == VREL_UNDEFINED) + if (is_and && vr1.intersect (vr2) && vr1.kind () == VREL_UNDEFINED) lhs_range = int_range<2> (boolean_false_node, boolean_false_node); // x || y is true if the union of the true cases is NO-RELATION.. // ie, one or the other being true covers the full range of possibilties. - else if (!is_and && relation_union (relation1, relation2) == VREL_VARYING) + else if (!is_and && vr1.union_ (vr2) && vr1.kind () == VREL_VARYING) lhs_range = bool_one; else return; diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc index 6f8a1b7e7d3..432828e2b13 100644 --- a/gcc/value-relation.cc +++ b/gcc/value-relation.cc @@ -782,7 +782,7 @@ value_relation::negate () // Perform an intersection between 2 relations. *this &&= p. bool -value_relation::intersect (value_relation &p) +value_relation::intersect (const value_relation &p) { // Save previous value relation_kind old = related; @@ -800,7 +800,7 @@ value_relation::intersect (value_relation &p) // Perform a union between 2 relations. *this ||= p. bool -value_relation::union_ (value_relation &p) +value_relation::union_ (const value_relation &p) { // Save previous value relation_kind old = related; @@ -1118,8 +1118,7 @@ dom_oracle::set_one_relation (basic_block bb, relation_kind k, tree op1, // will be the aggregate of all the previous ones. curr = find_relation_dom (bb, v1, v2); if (curr != VREL_VARYING) - k = relation_intersect (curr, k); - + vr.intersect (value_relation (curr, op1, op2)); bitmap_set_bit (bm, v1); bitmap_set_bit (bm, v2); bitmap_set_bit (m_relation_set, v1); @@ -1127,7 +1126,7 @@ dom_oracle::set_one_relation (basic_block bb, relation_kind k, tree op1, ptr = (relation_chain *) obstack_alloc (&m_chain_obstack, sizeof (relation_chain)); - ptr->set_relation (k, op1, op2); + ptr->set_relation (vr.kind (), op1, op2); ptr->m_next = m_relations[bbi].m_head; m_relations[bbi].m_head = ptr; } @@ -1528,9 +1527,9 @@ path_oracle::register_relation (basic_block bb, relation_kind k, tree ssa1, if (ssa1 == ssa2) return; + value_relation vr (k, ssa1, ssa2); if (dump_file && (dump_flags & TDF_DETAILS)) { - value_relation vr (k, ssa1, ssa2); fprintf (dump_file, " Registering value_relation (path_oracle) "); vr.dump (dump_file); fprintf (dump_file, " (root: bb%d)\n", bb->index); @@ -1538,9 +1537,9 @@ path_oracle::register_relation (basic_block bb, relation_kind k, tree ssa1, relation_kind curr = query_relation (bb, ssa1, ssa2); if (curr != VREL_VARYING) - k = relation_intersect (curr, k); + vr.intersect (value_relation (curr, ssa1, ssa2)); - if (k == VREL_EQ) + if (vr.kind () == VREL_EQ) { register_equiv (bb, ssa1, ssa2); return; @@ -1550,7 +1549,7 @@ path_oracle::register_relation (basic_block bb, relation_kind k, tree ssa1, bitmap_set_bit (m_relations.m_names, SSA_NAME_VERSION (ssa2)); relation_chain *ptr = (relation_chain *) obstack_alloc (&m_chain_obstack, sizeof (relation_chain)); - ptr->set_relation (k, ssa1, ssa2); + ptr->set_relation (vr.kind (), ssa1, ssa2); ptr->m_next = m_relations.m_head; m_relations.m_head = ptr; } diff --git a/gcc/value-relation.h b/gcc/value-relation.h index 664fd71c925..354a0fd4130 100644 --- a/gcc/value-relation.h +++ b/gcc/value-relation.h @@ -426,8 +426,8 @@ public: inline tree op1 () const { return name1; } inline tree op2 () const { return name2; } - bool union_ (value_relation &p); - bool intersect (value_relation &p); + bool union_ (const value_relation &p); + bool intersect (const value_relation &p); void negate (); bool apply_transitive (const value_relation &rel); -- 2.39.0 From patchwork Mon Jan 23 17:44:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 47270 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1733930wrn; Mon, 23 Jan 2023 09:46:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXuTeS/g9C74VU4ApKPMtTtS05FwFuGqZjc59B6zYwsBnN+6Z6in6cjKOFu9QU0mmpe/2j5M X-Received: by 2002:a17:907:76ac:b0:857:1e36:3b7b with SMTP id jw12-20020a17090776ac00b008571e363b7bmr25613550ejc.11.1674495967473; Mon, 23 Jan 2023 09:46:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674495967; cv=none; d=google.com; s=arc-20160816; b=MmHINEl77BVx0g0eTGlxhyA3azR9nUwGQcA/+TzHMz2D4MXT/vthQaLzdJYz+wQnB+ CqWKbEWOtZlW9uXaRbh4RRKvCSuPJMn2vJ0QOe7eepBeDTdW1yh4yQfIH1NgJdnV86sj AdsPw5H97VfBjSjnIOQNFKAtzLWu9N3bGDTbgKxxUPhDvz4ycVRyiXaQl5OIfRbPi4O8 86O1PHVcRQTdbuj888SQCDYwU3bksxOthNrcFgNRUYQDBYm/Eoj4hH+ORp/rPc4/JkfJ pZ6FvQ4IV1XwWfOpvqPKj3yT7qm4UCF4Nmb4hKR9EymslPFhd0ebHCegAm9evz0yqRV3 Whww== 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-language :subject:cc:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=tDYt9XEn+ybtpo6YY6Kuhkkq1qrFxuVx/84cBzMskMw=; b=FSmxQHUgm/inJc3oyKom3GGKxwVfJ7on50cA2pcJZ+PZH62TiK//N699Fztzui3QSx 16D7xhKkJ8XWEMCtR58OE1apTkzIxpomCqXgJhHtpCa7I5qN84RamOe+mjAANlJ7EWYc Ww25bCAdmhtl5XdTAIua0kMzNu9p45RasvjaYbQ+BNwdjovaf/FsuQwJ4sI+TW2J6cYV OMYxdNeqpvtlMEsvhY90/2N8v/xDfbmjgHjePewsPE9A5h2MtKeT9hCqijxhBX7SvD/q QtIQx9CL6QMfQYVPKxnoO7s5Od1TvMe2iNTpoI1dEoYvN5dpWUQ+Qr0i/03eEbbhoQBZ 89aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jWx6pu21; 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 dt14-20020a170907728e00b008318885e1f1si57984503ejc.176.2023.01.23.09.46.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 09:46:07 -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=jWx6pu21; 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 3FC913857437 for ; Mon, 23 Jan 2023 17:45:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3FC913857437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674495942; bh=tDYt9XEn+ybtpo6YY6Kuhkkq1qrFxuVx/84cBzMskMw=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=jWx6pu21CO12ITMLj9J8qXuOURRNcGk5djaoyFAR8FXPkPVPWhWniVpF4Bs8jQZCY 9MuxcaGO9B/Jh8gqh45PnGdVMBA723ybxc5wS2SKcHQ9klXKrRuZLaJ4Hfoft4KZY4 wU7WkOmimv+fNN38yYvRhYZ1if7/4hldy+cpuNAw= 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 15C133858C2D for ; Mon, 23 Jan 2023 17:44:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 15C133858C2D Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-592-N4VXPFVrNHKELRupaDqLOg-1; Mon, 23 Jan 2023 12:44:51 -0500 X-MC-Unique: N4VXPFVrNHKELRupaDqLOg-1 Received: by mail-qv1-f69.google.com with SMTP id lv8-20020a056214578800b0053477624294so6310468qvb.22 for ; Mon, 23 Jan 2023 09:44:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rH2sHTfE9Ut/zFmbAHEUFCQ7YnGDr1cAb/7B8oBhh9g=; b=ZPa6OiUmEDyXFJoYEfRU049HI2y9KUHuqr57vUBpjNQf7RGTT35ELfGodmQ2aepRYn 7AeH1ZGZRtMfjFSOs89PY+gFhAs83CgNVthBFXvxo32U4ORul7UrI1wTT6zColdOPGlY xpDUdPDRQdP+bYqPbBSiNGu/ikmiOGLy6HmElqylGDelomI7Q6Rxlb6dHDMYCNDjVD0H RkN/bH2dBSvnHCiIW80xErvIlz/JKgsIUhzEYYs9/ejE4B5vj9GXD4DWRoNztcdHVXTO WhcUf3SnjMPpCf8o8p7crD7SY3spfMyBZo0LXdzC9+qCtbOR/A1m6aZVEHMfHG7S91NL RHYg== X-Gm-Message-State: AFqh2krKy5f2aqyNl6E2s93/mN4mH5KnSMMkph4Qsl/zdUyBrtRUY3VD OA+R6rTEZDKvJMdhD+wncyVOqsfwzrscStDIXk99LDkKdkMQC/FluhgDYiwD7da63kDUi/rEJ0r zCe2pv6V6ZorJwVuyd7IPCIXAXQFHCJPvvY6RH1gcyn+BC2POvtceU6qFD640fO2rkN20Pw== X-Received: by 2002:a05:6214:2b82:b0:537:4bc1:d783 with SMTP id kr2-20020a0562142b8200b005374bc1d783mr15816392qvb.43.1674495890762; Mon, 23 Jan 2023 09:44:50 -0800 (PST) X-Received: by 2002:a05:6214:2b82:b0:537:4bc1:d783 with SMTP id kr2-20020a0562142b8200b005374bc1d783mr15816366qvb.43.1674495890437; Mon, 23 Jan 2023 09:44:50 -0800 (PST) Received: from ?IPV6:2607:fea8:a263:f600::27bf? ([2607:fea8:a263:f600::27bf]) by smtp.gmail.com with ESMTPSA id y10-20020a05620a25ca00b006fa4cac54a5sm32082161qko.72.2023.01.23.09.44.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Jan 2023 09:44:49 -0800 (PST) Message-ID: Date: Mon, 23 Jan 2023 12:44:48 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 To: gcc-patches Cc: "hernandez, aldy" , Jakub Jelinek , Richard Biener Subject: [PATCH 2/2] Add VREL_OTHER for FP unsupported relations. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, BODY_8BITS, 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod 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?1755836283720844574?= X-GMAIL-MSGID: =?utf-8?q?1755836283720844574?= This patch adds VREL_OTHER to represent another relation we do not understand.  It is used to represent the class fo relations arising from floating point that are currently not represented. IN GCC 14 we will determine exactly how to represent them, but for this release, this should prevent us from getting things wrong at least. if intersection produces UNDEFINED and either of the relations feeding it were <, <=, >, or >=   then it turns it to VR_OTHER.   the prevents false sides of branches from combining to produce  UNDEFINED when they end up being a known NAN. Union is adjusted such that < >, or <= >= also produce VREL_OTHER.   < > cannot be properly represented, and <= >= was producing VARYING, which is also not correct. Form the testcase:     :     cmp1_10 = x_8(D) <= y_9(D);     cmp2_11 = x_8(D) >= y_9(D);     _3 = cmp1_10 & cmp2_11;     if (_3 != 0)       goto ; [INV]     else       goto ; [INV] Relational : (x_8(D) == y_9(D))     :     // predicted unlikely by early return (on trees) predictor.     goto ; [INV]     :     _4 = ~cmp1_10;     _5 = ~cmp2_11;     _1 = cmp1_10 | cmp2_11;     _6 = ~_1;     if (_1 != 0)       goto ; [INV]     else       goto ; [INV] Relational : (x_8(D) unknown fp y_9(D))     :     // predicted unlikely by early return (on trees) predictor. The intersection "fix" is represented by the relation between x and y in BB5.  Without the patch, ti would be UNDEFINED and we do not want that. The union fix is what prevents us from folding the condition in bb_4.  Without it, x<=y union x >=y comes out VARYING, when in fact I believe it represents everything except a NAN. So with this fix, all the unrepresentative relations get lumped into VREL_OTHER so we at least don't get it wrong.  For next release we can take the time to figure out exactly how we want to proceed. This is currently in testing on x86_64-pc-linux-gnu, and assuming it bootstraps with no regressions (a combined patch did before splitting it in 2), OK for trunk?   OR does it need more tweaking? Andrew From 6947cfa03098eee46669ec2902e5f6e33c3cbe9a Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Fri, 20 Jan 2023 17:31:26 -0500 Subject: [PATCH 2/2] Add VREL_OTHER for FP unsupported relations. Add VREL_OTHER to represent floating point relations we do not yet support. PR tree-optimization/108447 gcc/ * value-relation.cc (kind_string): Add "unknown fp". (rr_negate_table): Add entry for VREL_OTHER. (rr_swap_table): Likewise. (rr_intersect_table): Likewise. (rr_union_table): Likewise. (rr_transitive_table): Likewise. (relation_to_code): Likewise. (value_relation::intersect): Handle floating point differences. (value_relation::union_): Likewise. * value-relation.h (enum relation_kind_t): Add VREL_OTHER. gcc/testsuite/ * gcc.dg/pr108447.c: New. --- gcc/testsuite/gcc.dg/pr108447.c | 33 +++++++++ gcc/value-relation.cc | 118 +++++++++++++++++++++----------- gcc/value-relation.h | 1 + 3 files changed, 113 insertions(+), 39 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr108447.c diff --git a/gcc/testsuite/gcc.dg/pr108447.c b/gcc/testsuite/gcc.dg/pr108447.c new file mode 100644 index 00000000000..cfbaba6d0aa --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108447.c @@ -0,0 +1,33 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +__attribute__((noipa)) int +foo (float x, float y) +{ + _Bool cmp1 = x <= y; + _Bool cmp2 = x >= y; + if (cmp1 && cmp2) + return 1; + else if (!cmp1 && !cmp2) + return -1; + return 0; +} + +int +main () +{ + if (foo (0.0f, __builtin_nanf ("")) != -1) + __builtin_abort (); + if (foo (__builtin_nanf (""), -42.0f) != -1) + __builtin_abort (); + if (foo (0.0f, -0.0f) != 1) + __builtin_abort (); + if (foo (42.0f, 42.0f) != 1) + __builtin_abort (); + if (foo (42.0f, -0.0f) != 0) + __builtin_abort (); + if (foo (0.0f, -42.0f) != 0) + __builtin_abort (); + return 0; +} + diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc index 432828e2b13..299a119827a 100644 --- a/gcc/value-relation.cc +++ b/gcc/value-relation.cc @@ -33,8 +33,8 @@ along with GCC; see the file COPYING3. If not see #include "dominance.h" static const char *kind_string[VREL_LAST] = -{ "varying", "undefined", "<", "<=", ">", ">=", "==", "!=", "pe8", "pe16", - "pe32", "pe64" }; +{ "varying", "undefined", "<", "<=", ">", ">=", "==", "!=", "unknown fp", + "pe8", "pe16", "pe32", "pe64" }; // Print a relation_kind REL to file F. @@ -47,7 +47,7 @@ print_relation (FILE *f, relation_kind rel) // This table is used to negate the operands. op1 REL op2 -> !(op1 REL op2). relation_kind rr_negate_table[VREL_LAST] = { VREL_VARYING, VREL_UNDEFINED, VREL_GE, VREL_GT, VREL_LE, VREL_LT, VREL_NE, - VREL_EQ }; + VREL_EQ, VREL_OTHER }; // Negate the relation, as in logical negation. @@ -60,7 +60,7 @@ relation_negate (relation_kind r) // This table is used to swap the operands. op1 REL op2 -> op2 REL op1. relation_kind rr_swap_table[VREL_LAST] = { VREL_VARYING, VREL_UNDEFINED, VREL_GT, VREL_GE, VREL_LT, VREL_LE, VREL_EQ, - VREL_NE }; + VREL_NE, VREL_OTHER }; // Return the relation as if the operands were swapped. @@ -75,28 +75,32 @@ relation_swap (relation_kind r) relation_kind rr_intersect_table[VREL_LAST][VREL_LAST] = { // VREL_VARYING { VREL_VARYING, VREL_UNDEFINED, VREL_LT, VREL_LE, VREL_GT, VREL_GE, VREL_EQ, - VREL_NE }, + VREL_NE, VREL_OTHER }, // VREL_UNDEFINED { VREL_UNDEFINED, VREL_UNDEFINED, VREL_UNDEFINED, VREL_UNDEFINED, - VREL_UNDEFINED, VREL_UNDEFINED, VREL_UNDEFINED, VREL_UNDEFINED }, + VREL_UNDEFINED, VREL_UNDEFINED, VREL_UNDEFINED, VREL_UNDEFINED, + VREL_UNDEFINED }, // VREL_LT { VREL_LT, VREL_UNDEFINED, VREL_LT, VREL_LT, VREL_UNDEFINED, VREL_UNDEFINED, - VREL_UNDEFINED, VREL_LT }, + VREL_UNDEFINED, VREL_LT, VREL_OTHER }, // VREL_LE { VREL_LE, VREL_UNDEFINED, VREL_LT, VREL_LE, VREL_UNDEFINED, VREL_EQ, - VREL_EQ, VREL_LT }, + VREL_EQ, VREL_LT, VREL_OTHER }, // VREL_GT { VREL_GT, VREL_UNDEFINED, VREL_UNDEFINED, VREL_UNDEFINED, VREL_GT, VREL_GT, - VREL_UNDEFINED, VREL_GT }, + VREL_UNDEFINED, VREL_GT, VREL_OTHER }, // VREL_GE { VREL_GE, VREL_UNDEFINED, VREL_UNDEFINED, VREL_EQ, VREL_GT, VREL_GE, - VREL_EQ, VREL_GT }, + VREL_EQ, VREL_GT, VREL_OTHER }, // VREL_EQ { VREL_EQ, VREL_UNDEFINED, VREL_UNDEFINED, VREL_EQ, VREL_UNDEFINED, VREL_EQ, - VREL_EQ, VREL_UNDEFINED }, + VREL_EQ, VREL_UNDEFINED, VREL_OTHER }, // VREL_NE { VREL_NE, VREL_UNDEFINED, VREL_LT, VREL_LT, VREL_GT, VREL_GT, - VREL_UNDEFINED, VREL_NE } }; + VREL_UNDEFINED, VREL_NE, VREL_OTHER }, +// VREL_OTHER + { VREL_OTHER, VREL_UNDEFINED, VREL_OTHER, VREL_OTHER, VREL_OTHER, + VREL_OTHER, VREL_OTHER, VREL_OTHER, VREL_OTHER } }; // Intersect relation R1 with relation R2 and return the resulting relation. @@ -113,28 +117,31 @@ relation_intersect (relation_kind r1, relation_kind r2) relation_kind rr_union_table[VREL_LAST][VREL_LAST] = { // VREL_VARYING { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, - VREL_VARYING, VREL_VARYING, VREL_VARYING }, + VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING }, // VREL_UNDEFINED { VREL_VARYING, VREL_UNDEFINED, VREL_LT, VREL_LE, VREL_GT, VREL_GE, - VREL_EQ, VREL_NE }, + VREL_EQ, VREL_NE, VREL_OTHER }, // VREL_LT { VREL_VARYING, VREL_LT, VREL_LT, VREL_LE, VREL_NE, VREL_VARYING, VREL_LE, - VREL_NE }, + VREL_NE, VREL_OTHER }, // VREL_LE { VREL_VARYING, VREL_LE, VREL_LE, VREL_LE, VREL_VARYING, VREL_VARYING, - VREL_LE, VREL_VARYING }, + VREL_LE, VREL_VARYING, VREL_OTHER }, // VREL_GT { VREL_VARYING, VREL_GT, VREL_NE, VREL_VARYING, VREL_GT, VREL_GE, VREL_GE, - VREL_NE }, + VREL_NE, VREL_OTHER }, // VREL_GE { VREL_VARYING, VREL_GE, VREL_VARYING, VREL_VARYING, VREL_GE, VREL_GE, - VREL_GE, VREL_VARYING }, + VREL_GE, VREL_VARYING, VREL_OTHER }, // VREL_EQ { VREL_VARYING, VREL_EQ, VREL_LE, VREL_LE, VREL_GE, VREL_GE, VREL_EQ, - VREL_VARYING }, + VREL_VARYING, VREL_OTHER }, // VREL_NE { VREL_VARYING, VREL_NE, VREL_NE, VREL_VARYING, VREL_NE, VREL_VARYING, - VREL_VARYING, VREL_NE } }; + VREL_VARYING, VREL_NE, VREL_OTHER }, +// VREL_OTHER + { VREL_VARYING, VREL_OTHER, VREL_OTHER, VREL_OTHER, VREL_OTHER, + VREL_OTHER, VREL_OTHER, VREL_OTHER, VREL_OTHER } }; // Union relation R1 with relation R2 and return the result. @@ -151,28 +158,31 @@ relation_union (relation_kind r1, relation_kind r2) relation_kind rr_transitive_table[VREL_LAST][VREL_LAST] = { // VREL_VARYING { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, - VREL_VARYING, VREL_VARYING, VREL_VARYING }, + VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING }, // VREL_UNDEFINED { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, - VREL_VARYING, VREL_VARYING, VREL_VARYING }, + VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING }, // VREL_LT { VREL_VARYING, VREL_VARYING, VREL_LT, VREL_LT, VREL_VARYING, VREL_VARYING, - VREL_LT, VREL_VARYING }, + VREL_LT, VREL_VARYING, VREL_VARYING }, // VREL_LE { VREL_VARYING, VREL_VARYING, VREL_LT, VREL_LE, VREL_VARYING, VREL_VARYING, - VREL_LE, VREL_VARYING }, + VREL_LE, VREL_VARYING, VREL_VARYING }, // VREL_GT { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_GT, VREL_GT, - VREL_GT, VREL_VARYING }, + VREL_GT, VREL_VARYING, VREL_VARYING }, // VREL_GE { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_GT, VREL_GE, - VREL_GE, VREL_VARYING }, + VREL_GE, VREL_VARYING, VREL_VARYING }, // VREL_EQ { VREL_VARYING, VREL_VARYING, VREL_LT, VREL_LE, VREL_GT, VREL_GE, VREL_EQ, - VREL_VARYING }, + VREL_VARYING, VREL_VARYING }, // VREL_NE { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, - VREL_VARYING, VREL_VARYING, VREL_VARYING } }; + VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING }, +// VREL_OTHER + { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, + VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING } }; // Apply transitive operation between relation R1 and relation R2, and // return the resulting relation, if any. @@ -187,7 +197,7 @@ relation_transitive (relation_kind r1, relation_kind r2) tree_code relation_to_code [VREL_LAST] = { ERROR_MARK, ERROR_MARK, LT_EXPR, LE_EXPR, GT_EXPR, GE_EXPR, EQ_EXPR, - NE_EXPR }; + NE_EXPR, ERROR_MARK }; // This routine validates that a relation can be applied to a specific set of // ranges. In particular, floating point x == x may not be true if the NaN bit @@ -784,17 +794,28 @@ value_relation::negate () bool value_relation::intersect (const value_relation &p) { - // Save previous value - relation_kind old = related; + relation_kind k; if (p.op1 () == op1 () && p.op2 () == op2 ()) - related = relation_intersect (kind (), p.kind ()); + k = relation_intersect (kind (), p.kind ()); else if (p.op2 () == op1 () && p.op1 () == op2 ()) - related = relation_intersect (kind (), relation_swap (p.kind ())); + k = relation_intersect (kind (), relation_swap (p.kind ())); else return false; - return old != related; + if (related == k) + return false; + + bool float_p = name1 && FLOAT_TYPE_P (TREE_TYPE (name1)); + if (float_p && p.kind () != k && k == VREL_UNDEFINED) + { + if (relation_lt_le_gt_ge_p (kind ()) + || relation_lt_le_gt_ge_p (p.kind ())) + k = VREL_OTHER; + } + + related = k; + return true; } // Perform a union between 2 relations. *this ||= p. @@ -802,17 +823,36 @@ value_relation::intersect (const value_relation &p) bool value_relation::union_ (const value_relation &p) { - // Save previous value - relation_kind old = related; + relation_kind k; if (p.op1 () == op1 () && p.op2 () == op2 ()) - related = relation_union (kind(), p.kind()); + k = relation_union (kind (), p.kind ()); else if (p.op2 () == op1 () && p.op1 () == op2 ()) - related = relation_union (kind(), relation_swap (p.kind ())); + k = relation_union (kind (), relation_swap (p.kind ())); else return false; - return old != related; + if (related == k) + return false; + + // (x < y) || (x > y) produces x != y, but this is not true with floats. + // (x <= y) || (x >= y) produces VARYING, which is also not true for floats. + // As they cannot be properly represented, use VREL_OTHER. + bool float_p = name1 && FLOAT_TYPE_P (TREE_TYPE (name1)); + if (float_p && p.kind () != k) + { + if (kind () == VREL_LT && p.kind () == VREL_GT) + k = VREL_OTHER; + else if (kind () == VREL_GT && p.kind () == VREL_LT) + k = VREL_OTHER; + else if (kind () == VREL_LE && p.kind () == VREL_GE) + k = VREL_OTHER; + else if (kind () == VREL_GE && p.kind () == VREL_LE) + k = VREL_OTHER; + } + + related = k; + return true; } // Identify and apply any transitive relations between REL diff --git a/gcc/value-relation.h b/gcc/value-relation.h index 354a0fd4130..c191de292c7 100644 --- a/gcc/value-relation.h +++ b/gcc/value-relation.h @@ -70,6 +70,7 @@ typedef enum relation_kind_t VREL_GE, // r1 >= r2 VREL_EQ, // r1 == r2 VREL_NE, // r1 != r2 + VREL_OTHER, // unrepresentatble floating point relation. VREL_PE8, // 8 bit partial equivalency VREL_PE16, // 16 bit partial equivalency VREL_PE32, // 32 bit partial equivalency -- 2.39.0