From patchwork Thu May 25 08:59:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 70056 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1DA233858430 for ; Thu, 25 May 2023 08:59:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DA233858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685005191; bh=yh8WQ/C0nbIFoUFN+Eq3mJClNypvl86JCySvLy2CAAc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kfsYiH5vihxXVjHqH7gDhEvPYc+tKBFRVnGv2HOWSahlK59knEYBSjs6voQAbdSVA TTjP0KQSzgPMhEnMw36+q8mCI6+S73g5kYp3hi36pVctn5h2LWu/el9agfv4syt25l 0J4ImqRpgpqRJpD8hwCZQKa41LgAp67FEWZMe41E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id E256F3858D3C for ; Thu, 25 May 2023 08:59:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E256F3858D3C Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 125931FD97 for ; Thu, 25 May 2023 08:59:22 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 0846A2C141 for ; Thu, 25 May 2023 08:59:21 +0000 (UTC) Date: Thu, 25 May 2023 08:59:21 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/109791 - expand &x + off for niter compute User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230525085951.1DA233858430@sourceware.org> The following makes expand_simple_operations expand POINTER_PLUS_EXPRs with variable offset when the base is invariant. That will allow to simplify address differences to offset differences in some cases. Note the patch doesn't follow the variable off chain as I don't have a testcase showing that's beneficial. Bootstrapped and tested on x86_64-unknown-linux-gnu. I'm going to push this when the last patch in the series tests OK and the testcase from PR109791 then can be added. PR tree-optimization/109791 * tree-ssa-loop-niter.cc (expand_simple_operations): Expand &x + off. --- gcc/tree-ssa-loop-niter.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index 5d398b67e68..159fdc8fb85 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -2817,12 +2817,17 @@ expand_simple_operations (tree expr, tree stop, hash_map &cache) return expr; /* Fallthru. */ case POINTER_PLUS_EXPR: - /* And increments and decrements by a constant are simple. */ + /* And increments and decrements by a constant are simple. + Also expand increments from an invariant base (but do not follow + a variable offset). */ e1 = gimple_assign_rhs2 (stmt); - if (!is_gimple_min_invariant (e1)) + if (is_gimple_min_invariant (e1)) + ee = expand_simple_operations (e, stop, cache); + else if (is_gimple_min_invariant (e)) + ee = e; + else return expr; - ee = expand_simple_operations (e, stop, cache); return fold_build2 (code, TREE_TYPE (expr), ee, e1); default: