From patchwork Wed Aug 17 01:16:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp2348044pxh; Tue, 16 Aug 2022 18:17:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Pumyb7MVvXriAVVJeh4oaLmt4qv+Npxlz/YKUZNI8fWDaOiu9ARslrbxrR7cLS0LDWYSd X-Received: by 2002:a17:906:7304:b0:730:c3a8:cd7a with SMTP id di4-20020a170906730400b00730c3a8cd7amr14681872ejc.575.1660699060683; Tue, 16 Aug 2022 18:17:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660699060; cv=none; d=google.com; s=arc-20160816; b=yJHfDbCkxBRAAlUXJvKB9YQhoR+QaLGmPOTY0W41NibuZA40c9iHPF0FW+OwOFg/1v PN1lY/gpkasyiOXUnffWyNT/wiyT5tZKEgzF/wvMcP8HEK0x3UDpIaLIWdbiVNUF8A9Y By7qkfb+cjYeyGQpUaU3iwK4DXe6tJGOKT3xGDnco3C2mGYYF5LC8cQp2dG1/LrtuECm Unw2NcL/IuSlpELTOqvQdGsQbjnaMx9TFmhwNZjv/rCaI1corhpDUFTytNVSsebeOQxs WoyxNzPViUA5B6p39+GBRRbC3rz7SGBw7jG93QBjQtNnuAhJEz5Vq524undkKUgn5BM/ 7+Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-language:in-reply-to:references:to:subject:user-agent :mime-version:date:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=mtJjSN/tO2DUrgGhSVuTs/erGhTsh/0t1/sOJQ/AuLs=; b=M1Q9JsxmNGThM7SmBcEipqjpT+qfODx61cZKnRajMrrlhDU1gxZBR01RObYByz5qKU 0pB9WL8OGkWTHueHBHaVLiArsyeb/nN01fPLuTlzcXg+CtGdIkDgc9xoZT9m/Ul2Is/V HsUi9u1+j646gGV4S5UqbpImmhtCigKCOni2UtoWVQ8/ugBOxrEGlO2vQdKSfyjIxCNy QMnnSAdhT5a3QnD1M5C4q8FyxgqdJ13gkhPQArMuq9wXS1eNkBZmJx7m/jlnP0d5sk7n nOxqKoV0gyxCM7a6gxQAnYUKJw36Q0bjXoyOEh+JwWEGc15Zv0Z6JuN5D1FLbgNYxTYa tYxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tsj+4c6t; 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 w1-20020a1709064a0100b00730936657d1si9645398eju.552.2022.08.16.18.17.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 18:17:40 -0700 (PDT) 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=tsj+4c6t; 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 10FF43858430 for ; Wed, 17 Aug 2022 01:17:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10FF43858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1660699058; bh=mtJjSN/tO2DUrgGhSVuTs/erGhTsh/0t1/sOJQ/AuLs=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=tsj+4c6tyGb4XjgOaoFMsTOs+5maP+nbb89q0vkWgDPNK4aFZUXsw7s8w7QuAGRSs Qk1dfxWc4EgUW7migFGqXWRitXFfFkaVguC+9+Hhgkpo/y1X/lxwIwx13c5xkKbh6e iHYZmjaDU87TswYt9+7AG9wit6sxBq22eRh4GAAA= 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 0894E3858C2D for ; Wed, 17 Aug 2022 01:16:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0894E3858C2D Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-491-z_2IhKt3ND6HgDj9mfaxkQ-1; Tue, 16 Aug 2022 21:16:48 -0400 X-MC-Unique: z_2IhKt3ND6HgDj9mfaxkQ-1 Received: by mail-io1-f70.google.com with SMTP id u5-20020a6b4905000000b00681e48dbd92so6992215iob.21 for ; Tue, 16 Aug 2022 18:16:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc; bh=iHlJije0mb/5rvhLBFOEP6dTFu99HPv8MnuyDcXIpqw=; b=UvvanJ56w4nobqhoRFX+eID3SyaKwOJ03gug36289ltc8YyQWUlH5p+6LgAmMzQblb +NRaIn4a2E09DVXSjgrg76kuCT4DUBStVPq8PZhyM25A9iMyJrE4JNeMtcwnAzrkkC6G o35/ZfzbEUNwHC1vuZsaeE+lRmEXC4CtJAaNaBlzelceos52Bzv1W5PHg1lazG4qBV0A jMn74kSmEmWFFe+IP+h3PU3M8lKlavDv3ggoOr1mbMIWGWhdWsHmfSWKeEPiFo2cTDEo 4C3rwpGAKts80zTvLi8tDghOg+7YDtu0YnI4OSy3fGlYHr+q8khQLRrp2eL11gyfQAyD JVeA== X-Gm-Message-State: ACgBeo1a0IMrSZHK9EJ8p6c6ITW/kDi1A7P5o4aAvQSx2hb2p1/xeaho fTs+FPT+R+9/M09uw3is7EZjX40dwRqyNiNW/cLoNVx8qQPAjJ2sjMtYy/P3Yd9eqkzsZG5bExU oxtubiSWckZcOAtC8OA== X-Received: by 2002:a05:6e02:1bce:b0:2e4:745b:d902 with SMTP id x14-20020a056e021bce00b002e4745bd902mr9294925ilv.265.1660699007568; Tue, 16 Aug 2022 18:16:47 -0700 (PDT) X-Received: by 2002:a05:6e02:1bce:b0:2e4:745b:d902 with SMTP id x14-20020a056e021bce00b002e4745bd902mr9294919ilv.265.1660699007311; Tue, 16 Aug 2022 18:16:47 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::8850? ([2607:fea8:a263:f600::8850]) by smtp.gmail.com with ESMTPSA id f17-20020a056602089100b0068869b84b02sm3083798ioz.21.2022.08.16.18.16.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Aug 2022 18:16:46 -0700 (PDT) Message-ID: <44b14867-3e77-6029-737e-386aa30d4b4f@redhat.com> Date: Tue, 16 Aug 2022 21:16:45 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [COMMITTED] Abstract interesting ssa-names from GORI. To: Aldy Hernandez , Richard Biener References: <73820.122081107421800679@us-mta-533.us.mimecast.lan> In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.0 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_LOW, 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 Cc: gcc-patches 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?1741369178250850515?= X-GMAIL-MSGID: =?utf-8?q?1741369178250850515?= On 8/16/22 04:21, Aldy Hernandez wrote: > On Thu, Aug 11, 2022 at 1:42 PM Richard Biener wrote: > >> @@ -599,6 +592,30 @@ path_range_query::compute_imports (bitmap imports, const vec &path) >> worklist.safe_push (arg); >> } >> } >> + else if (gassign *ass = dyn_cast (def_stmt)) >> + { >> + tree ssa[3]; >> + if (range_op_handler (ass)) >> + { >> + ssa[0] = gimple_range_ssa_p (gimple_range_operand1 (ass)); >> + ssa[1] = gimple_range_ssa_p (gimple_range_operand2 (ass)); >> + ssa[2] = NULL_TREE; >> + } >> + else if (gimple_assign_rhs_code (ass) == COND_EXPR) >> + { >> + ssa[0] = gimple_range_ssa_p (gimple_assign_rhs1 (ass)); >> + ssa[1] = gimple_range_ssa_p (gimple_assign_rhs2 (ass)); >> + ssa[2] = gimple_range_ssa_p (gimple_assign_rhs3 (ass)); >> + } >> + else >> + continue; >> + for (unsigned j = 0; j < 3; ++j) >> + { >> + tree rhs = ssa[j]; >> + if (rhs && add_to_imports (rhs, imports)) >> + worklist.safe_push (rhs); >> + } >> + } > We seem to have 3 copies of this copy now: this one, the > threadbackward one, and the original one. > > Could we abstract this somehow? > > Aldy > This particular code sequence processing range-ops and COND_EXPR is becoming more common, so I've abstracted it into a routine. Basically, pass it a vector and the stmt, and it will fill the first X elements with ssa-names from the stmt.  It only deals with range-ops and COND_EXPR for now, and it requires you pass it enough elements (3) so that it doesn't have to check if its overflowing the bounds.  It returns the number of names it put in the vector. This patch changes GORI to use the new routine.  Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew commit 80f78716c2c7ce1b7f96077c35c1dd474a2086a2 Author: Andrew MacLeod Date: Tue Aug 16 13:18:37 2022 -0400 Abstract interesting ssa-names from GORI. Provide a routine to pick out the ssa-names from interesting statements. * gimple-range-fold.cc (gimple_range_ssa_names): New. * gimple-range-fold.h (gimple_range_ssa_names): New prototype. * gimple-range-gori.cc (range_def_chain::get_def_chain): Move code to new routine. diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 689d8279627..b0b22106320 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -1580,3 +1580,36 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, edge e0, edge } } } + +// Given stmt S, fill VEC, up to VEC_SIZE elements, with relevant ssa-names +// on the statement. For efficiency, it is an error to not pass in enough +// elements for the vector. Return the number of ssa-names. + +unsigned +gimple_range_ssa_names (tree *vec, unsigned vec_size, gimple *stmt) +{ + tree ssa; + int count = 0; + + if (range_op_handler (stmt)) + { + gcc_checking_assert (vec_size >= 2); + if ((ssa = gimple_range_ssa_p (gimple_range_operand1 (stmt)))) + vec[count++] = ssa; + if ((ssa = gimple_range_ssa_p (gimple_range_operand2 (stmt)))) + vec[count++] = ssa; + } + else if (is_a (stmt) + && gimple_assign_rhs_code (stmt) == COND_EXPR) + { + gcc_checking_assert (vec_size >= 3); + gassign *st = as_a (stmt); + if ((ssa = gimple_range_ssa_p (gimple_assign_rhs1 (st)))) + vec[count++] = ssa; + if ((ssa = gimple_range_ssa_p (gimple_assign_rhs2 (st)))) + vec[count++] = ssa; + if ((ssa = gimple_range_ssa_p (gimple_assign_rhs3 (st)))) + vec[count++] = ssa; + } + return count; +} diff --git a/gcc/gimple-range-fold.h b/gcc/gimple-range-fold.h index c2f381dffec..f2eab720213 100644 --- a/gcc/gimple-range-fold.h +++ b/gcc/gimple-range-fold.h @@ -96,6 +96,14 @@ range_compatible_p (tree type1, tree type2) && TYPE_SIGN (type1) == TYPE_SIGN (type2)); } +extern tree gimple_range_operand1 (const gimple *s); +extern tree gimple_range_operand2 (const gimple *s); + +// Given stmt S, fill VEC, up to VEC_SIZE elements, with relevant ssa-names +// on the statement. For efficiency, it is an error to not pass in enough +// elements for the vector. Return the number of ssa-names. + +unsigned gimple_range_ssa_names (tree *vec, unsigned vec_size, gimple *stmt); // Source of all operands for fold_using_range and gori_compute. // It abstracts out the source of an operand so it can come from a stmt or @@ -150,9 +158,6 @@ protected: relation_oracle *m_oracle; }; -extern tree gimple_range_operand1 (const gimple *s); -extern tree gimple_range_operand2 (const gimple *s); - // This class uses ranges to fold a gimple statement producinf a range for // the LHS. The source of all operands is supplied via the fur_source class // which provides a range_query as well as a source location and any other diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 8879e44cba1..957b8d543fa 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -331,7 +331,7 @@ range_def_chain::has_def_chain (tree name) bitmap range_def_chain::get_def_chain (tree name) { - tree ssa1, ssa2, ssa3; + tree ssa[3]; unsigned v = SSA_NAME_VERSION (name); // If it has already been processed, just return the cached value. @@ -347,23 +347,10 @@ range_def_chain::get_def_chain (tree name) } gimple *stmt = SSA_NAME_DEF_STMT (name); - if (range_op_handler (stmt)) + unsigned count = gimple_range_ssa_names (ssa, 3, stmt); + if (count == 0) { - ssa1 = gimple_range_ssa_p (gimple_range_operand1 (stmt)); - ssa2 = gimple_range_ssa_p (gimple_range_operand2 (stmt)); - ssa3 = NULL_TREE; - } - else if (is_a (stmt) - && gimple_assign_rhs_code (stmt) == COND_EXPR) - { - gassign *st = as_a (stmt); - ssa1 = gimple_range_ssa_p (gimple_assign_rhs1 (st)); - ssa2 = gimple_range_ssa_p (gimple_assign_rhs2 (st)); - ssa3 = gimple_range_ssa_p (gimple_assign_rhs3 (st)); - } - else - { - // Stmts not understood are always imports. + // Stmts not understood or with no operands are always imports. set_import (m_def_chain[v], name, NULL); return NULL; } @@ -373,17 +360,13 @@ range_def_chain::get_def_chain (tree name) return NULL; // Increase the depth if we have a pair of ssa-names. - if (ssa1 && ssa2) + if (count > 1) m_logical_depth++; - register_dependency (name, ssa1, gimple_bb (stmt)); - register_dependency (name, ssa2, gimple_bb (stmt)); - register_dependency (name, ssa3, gimple_bb (stmt)); - // Stmts with no understandable operands are also imports. - if (!ssa1 && !ssa2 & !ssa3) - set_import (m_def_chain[v], name, NULL); + for (unsigned x = 0; x < count; x++) + register_dependency (name, ssa[x], gimple_bb (stmt)); - if (ssa1 && ssa2) + if (count > 1) m_logical_depth--; return m_def_chain[v].bm;