From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1685005162; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=yh8WQ/C0nbIFoUFN+Eq3mJClNypvl86JCySvLy2CAAc=; b=bFYSc0/BFiDXR91kcuO9N6haRvx2UQskFUgIUsjqZ/a2MZ9nUMGqsUbDpG+VwVm8izR9lC GYALI8/ee3wAFir6g/mUwk1+9HZmW0JeQMCWAXSIT4y23qIg2MHZ4gb8Wa4CXrl57huCQU 1dqyACZPKaTZJ2UXacmI729rBM9xV9A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1685005162; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=yh8WQ/C0nbIFoUFN+Eq3mJClNypvl86JCySvLy2CAAc=; b=wpcB6qf2oDxM4/4vkhnUt8NZLnub1pjpmJTFWPhaifLnCu2VoFxLDLtfA8tOehsHjbBbtX eVHbbL0r71e1TfAQ== 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) From: Richard Biener 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 Content-Type: text/plain; charset=US-ASCII 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 List-Id: Message-ID: <20230525085921.zM_dy1JTECNkydEU-whnuvOQfcpkVjSgBQwbE1zfcEE@z> 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: -- 2.35.3