From patchwork Wed Jul 5 23:08:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1804099 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=K26mN5Vc; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QxFhd32qWz20bK for ; Thu, 6 Jul 2023 09:08:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4B5DA3853D0D for ; Wed, 5 Jul 2023 23:08:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B5DA3853D0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688598527; bh=zqvod4wm82WLLcILuxy03DymOd6MxSpXSljKZQBVR4U=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=K26mN5VcZVU/6CTRxhLR6xrPIv2Lx6Ty00TuQPg7H9U4JF8NrT/vVsjciu1L/WOQM MMwcZAmi9RkHD9t9QAM98PnJU0IYqDY+Uk7cvIVf49uk2lSty7DhwU7GgI8JWSlJdF ifOosq0t/Bb2inBNAP3iCzuQf6GPssqwDCymleLI= 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 93F0F385559E for ; Wed, 5 Jul 2023 23:08:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 93F0F385559E Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-218-j57-KMlkMv2B-_0TiFtLUA-1; Wed, 05 Jul 2023 19:08:24 -0400 X-MC-Unique: j57-KMlkMv2B-_0TiFtLUA-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-635f12395b5so1854176d6.3 for ; Wed, 05 Jul 2023 16:08:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688598503; x=1691190503; 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=tR900KqOYrJcWGW1CHoWgGSfgJbKW5cm7EsI4p6IiNo=; b=VjJ+fnRxJOKnpTgSHObyqj6PGgLgYHRNguLk534gms11Mx6cEUEBcdCOEJMgHTztKp CMkTa85Eo5TkajySzVNyI/B8Xv/AjKi4unHCSvMqaoG6cXx0cr4r54tHhsiLWePJo4Od hkq4lWcZpzOuE5RqOroVxstSwuycrCr575Hmz2TQWLZduKThhAMObVGGoPhlQZDIJw7/ 1LmBplfd9n35d9mvZwWXe0cTMwFKgdPs9PD+Lr8M88TqYmKLtARi1YUuiEbYo9E1V7R5 p11AHVgMRto3cmh7MhbGJ3Gs6movzAoCMG7tuZCkx5qIKPTqI0p66aePV2Fd+QX3OoOC nGaw== X-Gm-Message-State: ABy/qLbY5Dj/QEPQz7z6LelwaRqp9WlYCpEQ4SLnX1AGmvqyI1J4NEBw oVFOT3kgRZ995Ez7b+Kbx1UDcTyr3N9w6Yw3BQanVVSuFxgYow+IpEWu4HKVdmJUUJtPT93V+GX CDWu/pZ5CAXPb/StR78yCxJHdaFieezfK5g8l2SEAP3KeZaLz2AuMYk6VQtdXofkqOfz9IIphF5 fKYA== X-Received: by 2002:a0c:ac0e:0:b0:619:4232:aa87 with SMTP id l14-20020a0cac0e000000b006194232aa87mr32596qvb.24.1688598503793; Wed, 05 Jul 2023 16:08:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlF1iRnHK+/GIJxtzKXoz9ceKFdIB5WW8UfHqmJNXWRBQ+hBwKiypAESxBpQOCWxeAPe55w/OA== X-Received: by 2002:a0c:ac0e:0:b0:619:4232:aa87 with SMTP id l14-20020a0cac0e000000b006194232aa87mr32581qvb.24.1688598503444; Wed, 05 Jul 2023 16:08:23 -0700 (PDT) Received: from [192.168.0.174] ([104.219.122.97]) by smtp.gmail.com with ESMTPSA id i4-20020a0cf484000000b0063013c621fasm53245qvm.68.2023.07.05.16.08.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Jul 2023 16:08:23 -0700 (PDT) Message-ID: <74df7fe5-ddc7-f200-78e9-8ce72f17b88b@redhat.com> Date: Wed, 5 Jul 2023 19:08:21 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: gcc-patches Cc: "hernandez, aldy" Subject: [COMMITTED 3/5] Make compute_operand1_range a leaf call. 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" now operand1 alone is resolved, and returned as the result.  much cleaner, and removes it from the recursion stack. compute_operand_range() will decide if further evaluation is required. Bootstraps on  x86_64-pc-linux-gnu  with no regressions.  Pushed. Andrew From 912b5ac49677160aada7a2d862273251406dfca5 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 5 Jul 2023 13:41:50 -0400 Subject: [PATCH 3/6] Make compute_operand1_range a leaf call. Rather than creating long call chains, put the onus for finishing the evlaution on the caller. * gimple-range-gori.cc (compute_operand_range): After calling compute_operand1_range, recursively call self if needed. (compute_operand1_range): Turn into a leaf function. (gori_compute::compute_operand1_and_operand2_range): Finish operand1 calculation. * gimple-range-gori.h (compute_operand1_range): Remove name param. --- gcc/gimple-range-gori.cc | 49 ++++++++++++++++++++-------------------- gcc/gimple-range-gori.h | 2 +- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 5429c6e3c1a..b66b9b0398c 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -637,7 +637,7 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, // Handle end of lookup first. if (op1 == name) - return compute_operand1_range (r, handler, lhs, name, src, vrel_ptr); + return compute_operand1_range (r, handler, lhs, src, vrel_ptr); if (op2 == name) return compute_operand2_range (r, handler, lhs, name, src, vrel_ptr); @@ -731,7 +731,15 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, 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, vrel_ptr); + { + Value_Range vr (TREE_TYPE (op1)); + if (!compute_operand1_range (vr, handler, lhs, src, vrel_ptr)) + return false; + gimple *src_stmt = SSA_NAME_DEF_STMT (op1); + gcc_checking_assert (src_stmt); + // Then feed this range back as the LHS of the defining statement. + return compute_operand_range (r, src_stmt, vr, name, src, vrel_ptr); + } else if (op2_in_chain) res = compute_operand2_range (r, handler, lhs, name, src, vrel_ptr); else @@ -1099,7 +1107,7 @@ gori_compute::refine_using_relation (tree op1, vrange &op1_range, bool gori_compute::compute_operand1_range (vrange &r, gimple_range_op_handler &handler, - const vrange &lhs, tree name, + const vrange &lhs, fur_source &src, value_relation *rel) { gimple *stmt = handler.stmt (); @@ -1112,7 +1120,6 @@ gori_compute::compute_operand1_range (vrange &r, trio = rel->create_trio (lhs_name, op1, op2); Value_Range op1_range (TREE_TYPE (op1)); - Value_Range tmp (TREE_TYPE (op1)); Value_Range op2_range (op2 ? TREE_TYPE (op2) : TREE_TYPE (op1)); // Fetch the known range for op1 in this block. @@ -1130,7 +1137,7 @@ gori_compute::compute_operand1_range (vrange &r, // If op1 == op2, create a new trio for just this call. if (op1 == op2 && gimple_range_ssa_p (op1)) trio = relation_trio (trio.lhs_op1 (), trio.lhs_op2 (), VREL_EQ); - if (!handler.calc_op1 (tmp, lhs, op2_range, trio)) + if (!handler.calc_op1 (r, lhs, op2_range, trio)) return false; } else @@ -1138,7 +1145,7 @@ gori_compute::compute_operand1_range (vrange &r, // We pass op1_range to the unary operation. Normally it's a // hidden range_for_type parameter, but sometimes having the // actual range can result in better information. - if (!handler.calc_op1 (tmp, lhs, op1_range, trio)) + if (!handler.calc_op1 (r, lhs, op1_range, trio)) return false; } @@ -1161,30 +1168,16 @@ gori_compute::compute_operand1_range (vrange &r, tracer.print (idx, "Computes "); print_generic_expr (dump_file, op1, TDF_SLIM); fprintf (dump_file, " = "); - tmp.dump (dump_file); + r.dump (dump_file); fprintf (dump_file, " intersect Known range : "); op1_range.dump (dump_file); fputc ('\n', dump_file); } - // Intersect the calculated result with the known result and return if done. - if (op1 == name) - { - tmp.intersect (op1_range); - r = tmp; - if (idx) - tracer.trailer (idx, "produces ", true, name, r); - return true; - } - // If the calculation continues, we're using op1_range as the new LHS. - op1_range.intersect (tmp); + r.intersect (op1_range); if (idx) - tracer.trailer (idx, "produces ", true, op1, op1_range); - gimple *src_stmt = SSA_NAME_DEF_STMT (op1); - 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, rel); + tracer.trailer (idx, "produces ", true, op1, r); + return true; } @@ -1291,7 +1284,13 @@ gori_compute::compute_operand1_and_operand2_range (vrange &r, return false; // Now get the range thru op1. - if (!compute_operand1_range (op_range, handler, lhs, name, src, rel)) + Value_Range vr (TREE_TYPE (handler.operand1 ())); + if (!compute_operand1_range (vr, handler, lhs, src, rel)) + return false; + gimple *src_stmt = SSA_NAME_DEF_STMT (handler.operand1 ()); + gcc_checking_assert (src_stmt); + // Then feed this range back as the LHS of the defining statement. + if (!compute_operand_range (op_range, src_stmt, vr, 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 526edc24b53..1d451fa7e9a 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -183,7 +183,7 @@ private: 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, 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, -- 2.40.1