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: 98902 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp215969vqr; Thu, 25 May 2023 02:00:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5jQ9VxqeP+HyE3OoVBXVgI0U3UiMFFc0S9nookxsKPVPD0cwFPUtzNSRF/b2IqOIg96Au5 X-Received: by 2002:a17:907:d26:b0:973:92a8:f611 with SMTP id gn38-20020a1709070d2600b0097392a8f611mr887160ejc.31.1685005208372; Thu, 25 May 2023 02:00:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685005208; cv=none; d=google.com; s=arc-20160816; b=fIE99HAOkG/5TDF9ULj6zAbmliP6iMMnCMmMuh+iTXregQAcPAsbX3+Z3VuR9dDkKJ N+6oQYZVUtNqJGVa6Eav7prrBDvf0v4rjSn8/4WvAybIM/G+bIWuwxK4yAoBGF0Cjk0O Q8SWvEKRRwGOl13lLSzsKY1pJHAyah/Sz/bjigRExXqqSYXdjM0aUjwy3y8AiDbs1Zj3 AQFxzJZ9ShUeh/7atgBoMCteB5r41dc4vdedXcORECUXRhZOR2nTHo7Zu5EwMN0r/FjF O9AoIgbOZlzM9IZP2CCf46d+XW4tzDGZ7YyM6d6Rz13vnvouWb9KXIxy2A0lf62XCfNP Rjog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=yh8WQ/C0nbIFoUFN+Eq3mJClNypvl86JCySvLy2CAAc=; b=TH1xvHasOjT1YeyPnFuOvl3XXR7NEwon4Cl9/KbHWKJXRQCpPE2o4MhYY0nbviVbol FEp/3W+PCQ4QepCusJnY2G1b1wS9EiZiWZ2epJBs5wU6u6d6oW0zzEfZ9sMJUJZ8qzRg ujG/t5iwKuEYUm4++VFQhPIgEv04Nfn8pafbgTNcybNeO8TbwrgKpOk4wYy9S+xWRqBN +wstVCxwGWjqQuVK995uRzgJxWstdaCiVJ9Hibln681dfaDuWLqj4VvMg23d1K76HAa7 sEbesHRmsdk2EsmJd6mmv0CWqlv2+uI92TdqAvSNUO88u81N1vCvZTtJ8Fq0UHpbdEML Y8dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=S87ME7Lx; 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 v1-20020a170906858100b0096f52f19ca8si672007ejx.904.2023.05.25.02.00.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 02:00:08 -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=S87ME7Lx; 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 E0AA93857702 for ; Thu, 25 May 2023 09:00:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0AA93857702 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685005206; 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=S87ME7LxYYsKQgyGiY//KBP+hfRBarsT3ced6g7iPdvK3Ux/cXTpYmNQm0Fq8EvzT DppJ80X06bAh9fSKihTKBPk0RTziYkRGcp4GnBFK2CtEIqFM5EgfG9pW1L+g7XxD6T oat5K0x+8kR8lyoO7u/nfeJXYdsyDE9pL/OtU77Y= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230525090006.E0AA93857702@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766856021495310275?= X-GMAIL-MSGID: =?utf-8?q?1766856021495310275?= 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: