From patchwork Thu Sep 29 22:36:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 58192 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A327A381DC3E for ; Thu, 29 Sep 2022 22:36:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A327A381DC3E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664491003; bh=kceb0/X0qj+pqNJAwynPI59UKdE8/H7nJgPzvLbGWpA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=w8ojBWME05ZahVq3J+/L78PtZFerHtYXL80vks4PxFjJ/XEE5vTkhcuDMZ4Y2Pic0 33IXDD4oDLsbufWbSEkvC1uQlhDdoiL65SK9WGq0XRcmM6TCtfrDvhCFxJYOdiLrET Z4QIx3lpaPjJ8aZq/4X5vYNGLSqeVyOa9+Jp4wu0= 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 4F3D43839DE9 for ; Thu, 29 Sep 2022 22:36:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4F3D43839DE9 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-502-Qs5xasvuOqKYAA5PhpZ2Iw-1; Thu, 29 Sep 2022 18:36:04 -0400 X-MC-Unique: Qs5xasvuOqKYAA5PhpZ2Iw-1 Received: by mail-qv1-f69.google.com with SMTP id h14-20020a0cf8ce000000b004af8dccd6ccso1865473qvo.19 for ; Thu, 29 Sep 2022 15:36:04 -0700 (PDT) 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; bh=MlzHSoOEZuBhWKBeQ+6sm5RQn4PP0CURIkrelnzBFh0=; b=UugoRYf7r3xI8enW3buXvDjxH+HWG1h2Eo6TLLbBNuty7jjLBq+FUbcRHJL7A6Mvlf cwU8wzTiNNq/mhNl6kf9pDZ13P7Si6nh6uLfSy6CTw2HAeY76+QKl9UHMugTceFuCXRp sa7G47YlT2qE1nRAQS6xT71brO3oSlfPvRHHzqqZkJP4TUUzOr4oWF9mcFaGYJ8glqDE udJzxi1KU3kVMSXvRIVbXfd0MQoh0ToiXiaVAa70Y1N+KiBU/co2sr751gMYrdyEvl8W A8DC+dvfwAqsf3tRTq4eb3PXEEfdMDklRl3M4NQhKI0QngHvTLtMbcyWKqUGM3mGSH5E KDCw== X-Gm-Message-State: ACrzQf09bpj3D2esv1rIL7UC+WnpSBEfKVNk/er9dnf1Q4mrEKeeAGGe Ag/9RunjfaTvQTZSA/FTN8EGBKcdlbLVFdUkuDcTLovE9IbfMkGV54CyYq2etCbhawJPvEY0nvJ MVTfkHVVEGfqXt8DyvOLqNdYexjWX23myodCzaPnv/q+pZNTTfHyOAMfFxFw+G6a9y7StTw== X-Received: by 2002:a05:622a:510:b0:35d:50dd:3062 with SMTP id l16-20020a05622a051000b0035d50dd3062mr4423983qtx.437.1664490963837; Thu, 29 Sep 2022 15:36:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5yaT5RAIER8osljQIFU4g5ufp5tJFeNfTtZKf/aOKUkcE+sYNS5VNCrBwvZi2rVTnQb946Rw== X-Received: by 2002:a05:622a:510:b0:35d:50dd:3062 with SMTP id l16-20020a05622a051000b0035d50dd3062mr4423964qtx.437.1664490963536; Thu, 29 Sep 2022 15:36:03 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id q19-20020a37f713000000b006bba46e5eeasm585148qkj.37.2022.09.29.15.36.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Sep 2022 15:36:02 -0700 (PDT) Message-ID: Date: Thu, 29 Sep 2022 18:36:01 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 To: gcc-patches Subject: [PATCH] Track value_relations in GORI. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.5 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, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch allows GORI to recognize and pass relations along the calculation chain.  This will allow relations between the LHS and the operand being calculated to be utilized in op1_range and op2_range. compute_operand_range will look to see if the current statement creates a relation between op1 and op2, and if it does, creates a relation record and a passes it down to the next routine. Ie: [0,0] = a_1 < b_2 would create a relation record for (a_1 >= b2) and pass it along the calculation chain to the various op1/op2 ranges for use in their calculations.  This patch merely creates and passes it around, it doesn't actually do anything with it yet. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From ec80adf4173f3626e6c7931a9c1ba3f760cb2364 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Thu, 22 Sep 2022 17:55:56 -0400 Subject: [PATCH 4/6] Track value_relations in GORI. This allows GORI to recognize and pass relations along the calculation chain. This will allow relations between the LHS and the operand being calculated to be utilized in op1_range and op2_range. * gimple-range-gori.cc (ori_compute::compute_operand_range): Create a relation record and pass it along when possible. (gori_compute::compute_operand1_range): Pass relation along. (gori_compute::compute_operand2_range): Ditto. (gori_compute::compute_operand1_and_operand2_range): Ditto. * gimple-range-gori.h (class gori_compute): Adjust prototypes. * gimple-range-op.cc (gimple_range_op_handler::calc_op1): Pass relation to op1_range call. (gimple_range_op_handler::calc_op2): Pass relation to op2_range call. * gimple-range-op.h (class gimple_range_op_handler): Adjust prototypes. --- gcc/gimple-range-gori.cc | 42 +++++++++++++++++++++++++++------------- gcc/gimple-range-gori.h | 14 ++++++++++---- gcc/gimple-range-op.cc | 12 ++++++------ gcc/gimple-range-op.h | 6 ++++-- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 40b2f2f6ae9..57a7e820749 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -603,8 +603,10 @@ gori_compute::compute_operand_range_switch (vrange &r, gswitch *s, bool gori_compute::compute_operand_range (vrange &r, gimple *stmt, const vrange &lhs, tree name, - fur_source &src) + fur_source &src, value_relation *rel) { + value_relation vrel; + value_relation *vrel_ptr = rel; // If the lhs doesn't tell us anything, neither will unwinding further. if (lhs.varying_p ()) return false; @@ -625,11 +627,23 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, tree op1 = gimple_range_ssa_p (handler.operand1 ()); tree op2 = gimple_range_ssa_p (handler.operand2 ()); + // If there is a relation, use it instead of any passed in. This will allow + // multiple relations to be processed in compound logicals. + if (op1 && op2) + { + relation_kind k = handler.op1_op2_relation (lhs); + if (k != VREL_VARYING) + { + vrel.set_relation (k, op1, op2); + vrel_ptr = &vrel; + } + } + // Handle end of lookup first. if (op1 == name) - return compute_operand1_range (r, handler, lhs, name, src); + return compute_operand1_range (r, handler, lhs, name, src, vrel_ptr); if (op2 == name) - return compute_operand2_range (r, handler, lhs, name, src); + return compute_operand2_range (r, handler, lhs, name, src, vrel_ptr); // NAME is not in this stmt, but one of the names in it ought to be // derived from it. @@ -672,11 +686,12 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, } // Follow the appropriate operands now. else if (op1_in_chain && op2_in_chain) - res = compute_operand1_and_operand2_range (r, handler, lhs, name, src); + res = compute_operand1_and_operand2_range (r, handler, lhs, name, src, + vrel_ptr); else if (op1_in_chain) - res = compute_operand1_range (r, handler, lhs, name, src); + res = compute_operand1_range (r, handler, lhs, name, src, vrel_ptr); else if (op2_in_chain) - res = compute_operand2_range (r, handler, lhs, name, src); + res = compute_operand2_range (r, handler, lhs, name, src, vrel_ptr); else gcc_unreachable (); @@ -927,7 +942,7 @@ bool gori_compute::compute_operand1_range (vrange &r, gimple_range_op_handler &handler, const vrange &lhs, tree name, - fur_source &src) + fur_source &src, value_relation *rel) { gimple *stmt = handler.stmt (); tree op1 = handler.operand1 (); @@ -998,7 +1013,7 @@ gori_compute::compute_operand1_range (vrange &r, gcc_checking_assert (src_stmt); // Then feed this range back as the LHS of the defining statement. - return compute_operand_range (r, src_stmt, op1_range, name, src); + return compute_operand_range (r, src_stmt, op1_range, name, src, rel); } @@ -1010,7 +1025,7 @@ bool gori_compute::compute_operand2_range (vrange &r, gimple_range_op_handler &handler, const vrange &lhs, tree name, - fur_source &src) + fur_source &src, value_relation *rel) { gimple *stmt = handler.stmt (); tree op1 = handler.operand1 (); @@ -1070,7 +1085,7 @@ gori_compute::compute_operand2_range (vrange &r, // gcc_checking_assert (!is_import_p (op2, find.bb)); // Then feed this range back as the LHS of the defining statement. - return compute_operand_range (r, src_stmt, op2_range, name, src); + return compute_operand_range (r, src_stmt, op2_range, name, src, rel); } // Calculate a range for NAME from both operand positions of S @@ -1083,17 +1098,18 @@ gori_compute::compute_operand1_and_operand2_range (vrange &r, &handler, const vrange &lhs, tree name, - fur_source &src) + fur_source &src, + value_relation *rel) { Value_Range op_range (TREE_TYPE (name)); // Calculate a good a range for op2. Since op1 == op2, this will // have already included whatever the actual range of name is. - if (!compute_operand2_range (op_range, handler, lhs, name, src)) + if (!compute_operand2_range (op_range, handler, lhs, name, src, rel)) return false; // Now get the range thru op1. - if (!compute_operand1_range (r, handler, lhs, name, src)) + if (!compute_operand1_range (r, handler, lhs, name, src, rel)) return false; // Both operands have to be simultaneously true, so perform an intersection. diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index 0c776ef853f..1fff3e6255a 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -153,6 +153,8 @@ private: // // The remaining routines are internal use only. +class value_relation; + class gori_compute : public gori_map { public: @@ -167,17 +169,21 @@ private: bool may_recompute_p (tree name, edge e); bool may_recompute_p (tree name, basic_block bb = NULL); bool compute_operand_range (vrange &r, gimple *stmt, const vrange &lhs, - tree name, class fur_source &src); + tree name, class fur_source &src, + value_relation *rel = NULL); bool compute_operand_range_switch (vrange &r, gswitch *s, const vrange &lhs, tree name, fur_source &src); bool compute_operand1_range (vrange &r, gimple_range_op_handler &handler, - const vrange &lhs, tree name, fur_source &src); + const vrange &lhs, tree name, fur_source &src, + value_relation *rel = NULL); bool compute_operand2_range (vrange &r, gimple_range_op_handler &handler, - const vrange &lhs, tree name, fur_source &src); + const vrange &lhs, tree name, fur_source &src, + value_relation *rel = NULL); bool compute_operand1_and_operand2_range (vrange &r, gimple_range_op_handler &handler, const vrange &lhs, tree name, - fur_source &src); + fur_source &src, + value_relation *rel = NULL); void compute_logical_operands (vrange &true_range, vrange &false_range, gimple_range_op_handler &handler, const irange &lhs, tree name, fur_source &src, diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index d7c6dfa933d..f6d2053f156 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -202,7 +202,7 @@ gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range) bool gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range, - const vrange &op2_range) + const vrange &op2_range, relation_kind k) { // Give up on empty ranges. if (lhs_range.undefined_p ()) @@ -225,9 +225,9 @@ gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range, op2_type = TREE_TYPE (operand1 ()); Value_Range trange (op2_type); trange.set_varying (op2_type); - return op1_range (r, type, lhs_range, trange); + return op1_range (r, type, lhs_range, trange, k); } - return op1_range (r, type, lhs_range, op2_range); + return op1_range (r, type, lhs_range, op2_range, k); } // Calculate what we can determine of the range of this statement's @@ -237,7 +237,7 @@ gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range, bool gimple_range_op_handler::calc_op2 (vrange &r, const vrange &lhs_range, - const vrange &op1_range) + const vrange &op1_range, relation_kind k) { // Give up on empty ranges. if (lhs_range.undefined_p ()) @@ -250,9 +250,9 @@ gimple_range_op_handler::calc_op2 (vrange &r, const vrange &lhs_range, tree op1_type = TREE_TYPE (operand1 ()); Value_Range trange (op1_type); trange.set_varying (op1_type); - return op2_range (r, type, lhs_range, trange); + return op2_range (r, type, lhs_range, trange, k); } - return op2_range (r, type, lhs_range, op1_range); + return op2_range (r, type, lhs_range, op1_range, k); } // -------------------------------------------------------------------- diff --git a/gcc/gimple-range-op.h b/gcc/gimple-range-op.h index 68764198bc0..3a555f29a65 100644 --- a/gcc/gimple-range-op.h +++ b/gcc/gimple-range-op.h @@ -35,8 +35,10 @@ public: tree operand1 () const { gcc_checking_assert (m_valid); return m_op1; } tree operand2 () const { gcc_checking_assert (m_valid); return m_op2; } bool calc_op1 (vrange &r, const vrange &lhs_range); - bool calc_op1 (vrange &r, const vrange &lhs_range, const vrange &op2_range); - bool calc_op2 (vrange &r, const vrange &lhs_range, const vrange &op1_range); + bool calc_op1 (vrange &r, const vrange &lhs_range, const vrange &op2_range, + relation_kind k = VREL_VARYING); + bool calc_op2 (vrange &r, const vrange &lhs_range, const vrange &op1_range, + relation_kind k = VREL_VARYING); private: void maybe_builtin_call (); gimple *m_stmt; -- 2.37.3