From patchwork Wed Jul 5 23:08:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1804100 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=iYw8t2+C; 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 4QxFjk4RNKz20bK for ; Thu, 6 Jul 2023 09:09:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 88DF43856090 for ; Wed, 5 Jul 2023 23:09:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88DF43856090 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688598584; bh=PTPnEV+N8O6JdBVxKlJlzBh4t+qx6seP0+it3YRkFAE=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=iYw8t2+CHl2wqXAOXugVElVPCRBurNToIKlcOSXYWIMOydaVq1XQ2xC8K6PJKM0oy d1RbCRB7uhC56rB49uBXtG4vfi7HPoGM4ofToJrovBT7+B70QE8ZwtJdMj9i5iMNY1 4R14J6jka2a76EbkKGxRdDFW17Y+Xfnzhq9WbQ/U= 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 09D3F385C8B1 for ; Wed, 5 Jul 2023 23:08:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 09D3F385C8B1 Received: from mail-ua1-f70.google.com (mail-ua1-f70.google.com [209.85.222.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-209-EEehNrJhPgG3xULLZoIH0Q-1; Wed, 05 Jul 2023 19:08:32 -0400 X-MC-Unique: EEehNrJhPgG3xULLZoIH0Q-1 Received: by mail-ua1-f70.google.com with SMTP id a1e0cc1a2514c-791ba72ab57so26922241.1 for ; Wed, 05 Jul 2023 16:08:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688598511; x=1691190511; 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=6PNAvqI1q1ZoEOKlHwGxg/0JuwqNgkcFJZRkx78Yk8w=; b=aTqPdrADIdp2gjmZPZhvC+SqsoxYCkfjGXoCCdoLEHYtLDu9/xAvotZcmyfBkOKH2t CwzrpKuBoSXcBcOMu31jzxjbxecL8icvTWLBa0JZhfb+Az08JQSo+GRvw+dAA1PDOiqD jnL/XgfgKTYq7IfS/R88HGXJ1NPfoPRh2kpoA6FsfuaWKgjZbbNnNwc7FUIq4SziQQTk 2NTsqDcBlzPeOzZIVtAZfw4UQ3JdE6ZudVaBsCvcVisw2D+tckYKJJoWq2bM9DUczpuk H00vCr7xHS8TJl4LqFzKWh+dUcFexeSaVTrXxUn+sIEj5M8PPhXk7b6CPeXSf0+7fo1u gm4Q== X-Gm-Message-State: ABy/qLZLOak7Pl1B9/WXgVQfFchcPempWfWLWih+9IhalawKjg7KVJ4v beXtSvgHHLj55lWQyK1vu/ycHdv/0mAPQCvYSQeYd9UGVgmdPEmgKymocEUWsk6T+kW0fuqNkVP 7yTo2JuaupH/j79BZnEgoNpu7XeWi4Frl9TpTZVvUyJDZ2RJQXyOZnQ78Ljfqn5fvQOmmqHRbIr jltQ== X-Received: by 2002:a05:6102:300c:b0:440:c0dd:e7f7 with SMTP id s12-20020a056102300c00b00440c0dde7f7mr436578vsa.4.1688598510974; Wed, 05 Jul 2023 16:08:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlF8UyiyaOplt28vQmnM7SUEjanS5ELwKJdhdmVD8wnnpDI8qnbl/UeJsevXKdaiCwsAWX6Psg== X-Received: by 2002:a05:6102:300c:b0:440:c0dd:e7f7 with SMTP id s12-20020a056102300c00b00440c0dde7f7mr436567vsa.4.1688598510695; Wed, 05 Jul 2023 16:08:30 -0700 (PDT) Received: from [192.168.0.174] ([104.219.122.97]) by smtp.gmail.com with ESMTPSA id m20-20020a0cdb94000000b00636e767d445sm53721qvk.62.2023.07.05.16.08.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Jul 2023 16:08:30 -0700 (PDT) Message-ID: Date: Wed, 5 Jul 2023 19:08:29 -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 4/5] Make compute_operand2_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 operand2 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 298952bcf05d298892e99adba1f4a75af17bc65a Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 5 Jul 2023 13:52:21 -0400 Subject: [PATCH 4/6] Make compute_operand2_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_operand2_range, recursively call self if needed. (compute_operand2_range): Turn into a leaf function. (gori_compute::compute_operand1_and_operand2_range): Finish operand2 calculation. * gimple-range-gori.h (compute_operand2_range): Remove name param. --- gcc/gimple-range-gori.cc | 52 +++++++++++++++++++--------------------- gcc/gimple-range-gori.h | 2 +- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index b66b9b0398c..b036ed56f02 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -639,7 +639,7 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, if (op1 == name) return compute_operand1_range (r, handler, lhs, src, vrel_ptr); if (op2 == name) - return compute_operand2_range (r, handler, lhs, name, src, vrel_ptr); + return compute_operand2_range (r, handler, lhs, src, vrel_ptr); // NAME is not in this stmt, but one of the names in it ought to be // derived from it. @@ -741,7 +741,15 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, 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); + { + Value_Range vr (TREE_TYPE (op2)); + if (!compute_operand2_range (vr, handler, lhs, src, vrel_ptr)) + return false; + gimple *src_stmt = SSA_NAME_DEF_STMT (op2); + 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 gcc_unreachable (); @@ -1188,7 +1196,7 @@ gori_compute::compute_operand1_range (vrange &r, bool gori_compute::compute_operand2_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 (); @@ -1198,7 +1206,6 @@ gori_compute::compute_operand2_range (vrange &r, Value_Range op1_range (TREE_TYPE (op1)); Value_Range op2_range (TREE_TYPE (op2)); - Value_Range tmp (TREE_TYPE (op2)); src.get_operand (op1_range, op1); src.get_operand (op2_range, op2); @@ -1215,7 +1222,7 @@ gori_compute::compute_operand2_range (vrange &r, if (op1 == op2 && gimple_range_ssa_p (op1)) trio = relation_trio (trio.lhs_op1 (), trio.lhs_op2 (), VREL_EQ); // Intersect with range for op2 based on lhs and op1. - if (!handler.calc_op2 (tmp, lhs, op1_range, trio)) + if (!handler.calc_op2 (r, lhs, op1_range, trio)) return false; unsigned idx; @@ -1237,31 +1244,16 @@ gori_compute::compute_operand2_range (vrange &r, tracer.print (idx, "Computes "); print_generic_expr (dump_file, op2, TDF_SLIM); fprintf (dump_file, " = "); - tmp.dump (dump_file); + r.dump (dump_file); fprintf (dump_file, " intersect Known range : "); op2_range.dump (dump_file); fputc ('\n', dump_file); } // Intersect the calculated result with the known result and return if done. - if (op2 == name) - { - tmp.intersect (op2_range); - r = tmp; - if (idx) - tracer.trailer (idx, " produces ", true, NULL_TREE, r); - return true; - } - // If the calculation continues, we're using op2_range as the new LHS. - op2_range.intersect (tmp); - + r.intersect (op2_range); if (idx) - tracer.trailer (idx, " produces ", true, op2, op2_range); - gimple *src_stmt = SSA_NAME_DEF_STMT (op2); - gcc_checking_assert (src_stmt); -// 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, rel); + tracer.trailer (idx, " produces ", true, op2, r); + return true; } // Calculate a range for NAME from both operand positions of S @@ -1279,15 +1271,21 @@ gori_compute::compute_operand1_and_operand2_range (vrange &r, { Value_Range op_range (TREE_TYPE (name)); + Value_Range vr (TREE_TYPE (handler.operand2 ())); // Calculate a good a range through op2. - if (!compute_operand2_range (r, handler, lhs, name, src, rel)) + if (!compute_operand2_range (vr, handler, lhs, src, rel)) + return false; + gimple *src_stmt = SSA_NAME_DEF_STMT (handler.operand2 ()); + gcc_checking_assert (src_stmt); + // Then feed this range back as the LHS of the defining statement. + if (!compute_operand_range (r, src_stmt, vr, name, src, rel)) return false; // Now get the range thru op1. - Value_Range vr (TREE_TYPE (handler.operand1 ())); + vr.set_type (TREE_TYPE (handler.operand1 ())); if (!compute_operand1_range (vr, handler, lhs, src, rel)) return false; - gimple *src_stmt = SSA_NAME_DEF_STMT (handler.operand1 ()); + 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)) diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index 1d451fa7e9a..b8d97d1dd72 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -186,7 +186,7 @@ private: 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, + const vrange &lhs, fur_source &src, value_relation *rel = NULL); bool compute_operand1_and_operand2_range (vrange &r, gimple_range_op_handler &handler, -- 2.40.1