From patchwork Fri Nov 11 16:17:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 18898 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp837000wru; Fri, 11 Nov 2022 08:18:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf4hX8XfnAI3q0zJ4kPO7PNA4lOKpApyKeLmQFCjCyYC3eX14GfVK9zyUCHfqge+V7uHi3JB X-Received: by 2002:a17:907:d68b:b0:7ae:41e6:9076 with SMTP id wf11-20020a170907d68b00b007ae41e69076mr2511555ejc.321.1668183486664; Fri, 11 Nov 2022 08:18:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668183486; cv=none; d=google.com; s=arc-20160816; b=OBsfQaUmqCI0dyzrQ5biH5X4lPJVv/IjCWDn+BGbxc1Gm+ti7G+2L1E9el3ae2/Igk Jb1PPm+Rj99tkhI8TfVos+xqqgsBOFNjj1GFxtmkbIRu0ONm9mplo7NGGXbLndVulUCe 9KlDqm5Vlz7dEbU8zBmZgwLXSpekAkK6ObgCEtzfBvrYl79Jsk4LFsoZx6eh7gkShmBh HjtKGRoIQsVJ6WcHWt1nTzUB94BHNKIsJ4CkGHL7/R3ZPT3wsifCqL8ZwPFsKsIFcsRj ch4cdv4QPcPAidQXn53+fW31SbOeXsOJXr2ULx3GhKVJ6yTzAXKXyciIDbEq2haTxFC9 Fzng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:content-language :subject:cc:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=ebcM7Gav85oTeV5K82ApFwwLfmgmwx2pG+vuk+iQv8A=; b=zV5DJ+qNxSkpx8mzWmbFiBWA9FgCSXVZo0sck3k1MPzTew3eDqShx4GTEL29Wc0JWw pg3PeSAZKVVl+I0FCu+zaFGNTm7fn5Pu4BfHdPUH8tLk+9NF1g5r9rDZyVoY77ReU4XA iAZBGgNIQMIHKPvOUS0J9GXr4pmJWZLi5qG6S92g7jA3uGU/a/3PY6KFysVL8cZvX0b6 l0a5lYPRGJaCp5umhAEUBKGHgUdEbdzyBfN1c91dkzygDyKPLcNLJGBXHkFs8tC/GDvM /4LA77mrCtEbof7ibAhZO8o5Xr5K/h0TdafokXS4i7Z0mLWmUmVHmQP1TZWKN8nhzTAO dJdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DR7Twg9v; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id jl8-20020a17090775c800b0078dc3cb8b48si1737548ejc.625.2022.11.11.08.18.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 08:18:06 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DR7Twg9v; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 B306D3858438 for ; Fri, 11 Nov 2022 16:18:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B306D3858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668183485; bh=ebcM7Gav85oTeV5K82ApFwwLfmgmwx2pG+vuk+iQv8A=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=DR7Twg9vDUxOTM3teYCFw/ToYlsqQUg8HvLhEwRb4JpSql86oVW6J2d0JBz5wDhAF jvBdiu18iylmIofuW91jNrQlubeIw0irMdKW4f+9KPIbMyORC6PZyh3opcIvAoWVuT JmbcP81B3p7Ey+99xXbO3W7c8Ysm6MNxcA0/YGRA= 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 B23823858D39 for ; Fri, 11 Nov 2022 16:17:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B23823858D39 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-349-Fa2GR12LP02jsxBGOXRHlw-1; Fri, 11 Nov 2022 11:17:20 -0500 X-MC-Unique: Fa2GR12LP02jsxBGOXRHlw-1 Received: by mail-qk1-f198.google.com with SMTP id bq13-20020a05620a468d00b006fa5a75759aso5098869qkb.13 for ; Fri, 11 Nov 2022 08:17:20 -0800 (PST) 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:message-id :reply-to; bh=8ThrvJ909KESl07+slLxeQQZ6/hQ4xw+M8OVTx1o4Fc=; b=y3hXO9B7kRzckCOY1B9UJeoF/3AZ7M2nxl60EnfIUVjB/vo9nYU/ElwVAgBGp2rNRL 6Cl7O1Esk+dqZJ4LPypNoqYoOxY3ZYUc0mkhUZAmVzZK9dNTZ7EzY414tQ1oDhEqMNaS /yHxh6Ecd3VY+aN37aFUKFQsQZbSRq5Qq6mzQrl8JYr9KH9DlrmJP7R6s9gofc48qqml xIhXCbgGmxavdc140urN/4yNoddjUlO2kEl5A8ttAyvLNCxUPijKTFi7IwBXvHPktPJb DLYX0QLmKVOB9Wdzmk4tdKMZ/WG5AvQ/ia8aikpDwNxvanhPvVDiiOA9kjPBiMu5rW6r 0MZg== X-Gm-Message-State: ANoB5pn0ghZFTqJDE0UD1WlAQxijFUAbB759wj7N4cDhnhmjdH+7buZB Zu++4KEJQcTLiL2NwV26mWCzqxUEiW0ZuVZKUPUZyOIRLbzwM1cXDNODZh2+1OfzDq4fiimiaiI v24rxz1SndZq944YCd3IYzGJvDwf1xGMztVKilUitRpzdAC5iv8g+5u2jJmWXO5l0zRu2PA== X-Received: by 2002:ac8:7607:0:b0:3a5:2bd0:67a4 with SMTP id t7-20020ac87607000000b003a52bd067a4mr1925048qtq.428.1668183440101; Fri, 11 Nov 2022 08:17:20 -0800 (PST) X-Received: by 2002:ac8:7607:0:b0:3a5:2bd0:67a4 with SMTP id t7-20020ac87607000000b003a52bd067a4mr1925025qtq.428.1668183439740; Fri, 11 Nov 2022 08:17:19 -0800 (PST) Received: from ?IPV6:2605:8d80:5e0:437a:2282:98c9:8765:f263? ([2605:8d80:5e0:437a:2282:98c9:8765:f263]) by smtp.gmail.com with ESMTPSA id y11-20020ac87c8b000000b0039d085a2571sm1440923qtv.55.2022.11.11.08.17.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Nov 2022 08:17:18 -0800 (PST) Message-ID: <3c68cb87-a088-85a0-0379-6aa893e36796@redhat.com> Date: Fri, 11 Nov 2022 11:17:17 -0500 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 Cc: "hernandez, aldy" Subject: [COMMITTED] process transitive inferred ranges in pre_fold_stmt. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.3 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_H2, 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749217167986066282?= X-GMAIL-MSGID: =?utf-8?q?1749217167986066282?= I was processing the transitive inferred ranges in fold_stmt when it was the final statement in the block.  the substitute_and_fold engine actually does a bit of work before calling fold_stmt.  this patch moves the check to pre_fold_stmt instead so it gets done before the final statement in the block is processed... as was the original intention. I also changed it so we always do this just before the last statement in any block.  This allows us to get transitive inferred ranges registered for returns, as well as just normal blocks which can feed other blocks.   Performance impact is minimal. Bootstraped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrei From dab5d73959cfc8f03cba548777adda9a798e1f0e Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 9 Nov 2022 10:58:15 -0500 Subject: [PATCH] process transitive inferred ranges in pre_fold_stmt. The subst_and_fold engine can perform some folding activity before calling fold_stmt, so do this work in pre_fold_stmt instead. * tree-vrp.cc (rvrp_folder::rvrp_folder): Init m_last_bb_stmt. (rvrp_folder::pre_fold_bb): Set m_last_bb_stmt. (rvrp_folder::pre_fold_stmt): Check for transitive inferred ranges. (rvrp_folder::fold_stmt): Check in pre_fold_stmt instead. --- gcc/tree-vrp.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc index 3393c73a7db..a474d9d11e5 100644 --- a/gcc/tree-vrp.cc +++ b/gcc/tree-vrp.cc @@ -4442,6 +4442,7 @@ public: { m_ranger = r; m_pta = new pointer_equiv_analyzer (m_ranger); + m_last_bb_stmt = NULL; } ~rvrp_folder () @@ -4485,6 +4486,7 @@ public: for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) m_ranger->register_inferred_ranges (gsi.phi ()); + m_last_bb_stmt = last_stmt (bb); } void post_fold_bb (basic_block bb) override @@ -4497,19 +4499,14 @@ public: void pre_fold_stmt (gimple *stmt) override { m_pta->visit_stmt (stmt); + // If this is the last stmt and there are inferred ranges, reparse the + // block for transitive inferred ranges that occur earlier in the block. + if (stmt == m_last_bb_stmt) + m_ranger->register_transitive_inferred_ranges (gimple_bb (stmt)); } bool fold_stmt (gimple_stmt_iterator *gsi) override { - gimple *s = gsi_stmt (*gsi); - // If this is a block ending condition, and there are inferred ranges, - // reparse the block to see if there are any transitive inferred ranges. - if (is_a (s)) - { - basic_block bb = gimple_bb (s); - if (bb && s == gimple_outgoing_range_stmt_p (bb)) - m_ranger->register_transitive_inferred_ranges (bb); - } bool ret = m_simplifier.simplify (gsi); if (!ret) ret = m_ranger->fold_stmt (gsi, follow_single_use_edges); @@ -4523,6 +4520,7 @@ private: gimple_ranger *m_ranger; simplify_using_ranges m_simplifier; pointer_equiv_analyzer *m_pta; + gimple *m_last_bb_stmt; }; /* Main entry point for a VRP pass using just ranger. This can be called -- 2.37.3