From patchwork Wed Jul 5 23:08:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1804097 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=ZcHmwWGb; 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 4QxFhX1YQ0z20bK for ; Thu, 6 Jul 2023 09:08:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F8DF385DC0C for ; Wed, 5 Jul 2023 23:08:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F8DF385DC0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688598519; bh=INy+ORYWLhSi1lXdYTgN9NGeC2DsFafks3m5Zo0Ewho=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ZcHmwWGbRMHSAjpl91pmOVgnGl9aUYT5wHLkgu1v1yaxgcXVmcnlmCo3h4cf5/Qtn NlxO6CYPpi1j27xDlkKXBSFlLk9pR30uPt9Uw1CV4HB4CY2ZNGOwIPo9nTnozJ4ZyK 0bNA/VrZ09a9KwxbwsUsC702XB3tfvsUtMfEPQSs= 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 D7F603856951 for ; Wed, 5 Jul 2023 23:08:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D7F603856951 Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-225-_uLUdtd9MUGKV41WzrZgcA-1; Wed, 05 Jul 2023 19:08:17 -0400 X-MC-Unique: _uLUdtd9MUGKV41WzrZgcA-1 Received: by mail-ot1-f70.google.com with SMTP id 46e09a7af769-6b754fb0220so49236a34.2 for ; Wed, 05 Jul 2023 16:08:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688598496; x=1691190496; 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=EFRxYldvzk/yNEcnw6nSgOO/dO+b5mRGRDcnCLnuxzY=; b=gQReU8yfvEPZYg7dEb5+MMU5zwAH7x+bedWBtMtE3h+bhxuete+TJkm8IuRoHoPwJ3 5txg5m6jf//QgRqOKf7D/8JBSx9+887fBwvVofm+LNJui+qPTECT/PScR00e9wh+tFDg 3q6gjMeT4ZkQ3VTMDYwDpgbDtZNwAzv+UhiGV09t34bV8tDFY6PfltjLLQ2ks0IL9uN9 gMcX8NbOz7zzQatx2MI3FfnqF5vxXR9JYPHUAOQiiRr9YC8+S96yynoSBVUO6Wf/c2ZQ fRbOlj03dfCpgeXkuN4q/fYO9067lBDc35FzN1aqOv261i5ZUA1nK6egprcJss7KvHQf 3hkA== X-Gm-Message-State: ABy/qLaETo0qUyaHK1Xay5nlyqfggC8Njmvx73HHW28MHNuVAwdOf3YC OkUVbUiPUHSYWTvUF4BnhKwmGx8Nzu4qpqsG0fSpVMmysPtfZUfiqwyGxD57aqFH9SG45Jf1t6j DDMODhmke28fETREPpJiQORkiQPu6CV7P/ASZ6u2B+6rogzFUbYh2xyKDGx+7m82TK51cMi7RML Tnmw== X-Received: by 2002:a05:6358:706:b0:134:d4c3:c47d with SMTP id e6-20020a056358070600b00134d4c3c47dmr255881rwj.6.1688598495840; Wed, 05 Jul 2023 16:08:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlEr5N+S3sOcqCmNTpjJ3aOyMjY7jFWc7nCX0YY96vbllR0sOixe6SzFD9+VqechzuOmMJZrRQ== X-Received: by 2002:a05:6358:706:b0:134:d4c3:c47d with SMTP id e6-20020a056358070600b00134d4c3c47dmr255866rwj.6.1688598495462; Wed, 05 Jul 2023 16:08:15 -0700 (PDT) Received: from [192.168.0.174] ([104.219.122.97]) by smtp.gmail.com with ESMTPSA id d26-20020a05620a137a00b0076719d9baeesm128641qkl.113.2023.07.05.16.08.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Jul 2023 16:08:15 -0700 (PDT) Message-ID: Date: Wed, 5 Jul 2023 19:08:14 -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 2/5] Simplify compute_operand_range for op1 and op2 case. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.8 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" This patch simplifies compute_operand1_and_operand2() such that it only calls each routine one. This will simplify the next couple of patches. It also allows moves the determination that op1 and op2 have an interdependence to  compute_operand_range(). Bootstraps on  x86_64-pc-linux-gnu  with no regressions.  Pushed. Andrew From 7276248946d3eae83e5e08fc023163614c9ea9ab Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 5 Jul 2023 13:36:27 -0400 Subject: [PATCH 2/6] Simplify compute_operand_range for op1 and op2 case. Move the check for co-dependency between 2 operands into compute_operand_range, resulting in a much cleaner compute_operand1_and_operand2_range routine. * gimple-range-gori.cc (compute_operand_range): Check for operand interdependence when both op1 and op2 are computed. (compute_operand1_and_operand2_range): No checks required now. --- gcc/gimple-range-gori.cc | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index b0d13a8ac53..5429c6e3c1a 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -650,6 +650,17 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, if (!op1_in_chain && !op2_in_chain) return false; + // If either operand is in the def chain of the other (or they are equal), it + // will be evaluated twice and can result in an exponential time calculation. + // Instead just evaluate the one operand. + if (op1_in_chain && op2_in_chain) + { + if (in_chain_p (op1, op2) || op1 == op2) + op1_in_chain = false; + else if (in_chain_p (op2, op1)) + op2_in_chain = false; + } + bool res = false; // If the lhs doesn't tell us anything only a relation can possibly enhance // the result. @@ -1275,24 +1286,10 @@ gori_compute::compute_operand1_and_operand2_range (vrange &r, { Value_Range op_range (TREE_TYPE (name)); - // If op1 is in the def chain of op2, we'll do the work twice to evalaute - // op1. This can result in an exponential time calculation. - // Instead just evaluate op2, which will eventualy get to op1. - if (in_chain_p (handler.operand1 (), handler.operand2 ())) - return compute_operand2_range (r, handler, lhs, name, src, rel); - - // Likewise if op2 is in the def chain of op1. - if (in_chain_p (handler.operand2 (), handler.operand1 ())) - return compute_operand1_range (r, handler, lhs, name, src, rel); - // Calculate a good a range through op2. if (!compute_operand2_range (r, handler, lhs, name, src, rel)) return false; - // If op1 == op2 there is again no need to go further. - if (handler.operand1 () == handler.operand2 ()) - return true; - // Now get the range thru op1. if (!compute_operand1_range (op_range, handler, lhs, name, src, rel)) return false; -- 2.40.1