From patchwork Tue Oct 25 08:02:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 10577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp869798wru; Tue, 25 Oct 2022 01:03:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6czbmzky19LJ90oWFEMy2f83NNVyJtB9cZKuM19JTDHdmsNbt040JN4sd1S5MP6qWsiSua X-Received: by 2002:a17:907:75d5:b0:78d:ef76:da7d with SMTP id jl21-20020a17090775d500b0078def76da7dmr31330846ejc.476.1666685020383; Tue, 25 Oct 2022 01:03:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666685020; cv=none; d=google.com; s=arc-20160816; b=hRxwazWCpryaQCsybaXy5FY/jL315yGDT+cZyjx+lIASl7ZLRi3k9Vo7uXIaa9uu6K w991E64bIP0nLX3kpTvx8pdNolA7y1EYi8dDNrmKQe3UmsrAzb+G0/CYiMe7JnGhZF1C IQ7AYNkZYEYe3u6xpa20mVwyN4JTngvRgH73mLpujMB2yvYPVsasGwWmharJLSuRYgC3 j8qBqhQ+Bbz5kH27CQumzPKB4wU3Yer3UnNjSnL+VyDQ9LVTy/gMnYz2djnu3bTYzMkM 2fjhQgTawtTj8bH/yRU1NEl9I1yYzXoCF0wPRRuhRSuaYMhqGExghy2s7qgqU5Q8TALy +Bbw== 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:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=u50kouI+EsUb7ZLUHL8kPLAX8pRnmFS+R9JTdckkcrk=; b=ubao8nlU6iAQ9Kr83QjJc3p+03mljTk+mLcA1+XP5x4oDhGDD52uS+LCV9T+xdsuqp U+T1w/4+vGDLraZsJxHA/U8ad4c7iq+5oBzCJAj+zqlGGTQhRANFSvmmVfMAnLEy5woM FmCF0DGGmnfYuGtdmrcMq2rotEgmjh0NOHHjlkfM9YKeKk2eJewkzok4eqhr7Fjx7aid qddZuQ/xzv3lfO+knMu+KxB+xwl0MK1fweW0n1Let972tV6LkkG1PoZ/DO1dDXrg1yu/ NNxUpEYJlosI/7Z2F+5Hyb7UKIKOx/uDSMesvCrj5wPFwkA4EISA49/X6aI7ZpBhIFUB b8QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FycRMD6E; 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 i6-20020aa7c9c6000000b00459f6d1be02si1851976edt.387.2022.10.25.01.03.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 01:03:40 -0700 (PDT) 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=FycRMD6E; 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 8395F3857416 for ; Tue, 25 Oct 2022 08:03:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8395F3857416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666685018; bh=u50kouI+EsUb7ZLUHL8kPLAX8pRnmFS+R9JTdckkcrk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FycRMD6EOXDfgeWkBa/w9H6wt2g5eqx2jW/bKBomnNlOdzWJAQgzYiqKsgpFdbU4K b12IW75CsAsdZ43pt7i2o2K7qh524NaloxIuRQzZd3gOFQReE6dRj+s09u115F7hTD bJPvP2tyEY8T3GrFopJN/A5S28JKxJiqLVYsSDNk= 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 [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id E597438582AD for ; Tue, 25 Oct 2022 08:02:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E597438582AD Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D20201FD6C for ; Tue, 25 Oct 2022 08:02:30 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C01D613A64 for ; Tue, 25 Oct 2022 08:02:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id p3b+LRaYV2MtEQAAMHmgww (envelope-from ) for ; Tue, 25 Oct 2022 08:02:30 +0000 Date: Tue, 25 Oct 2022 10:02:30 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/100756 - niter analysis and folding MIME-Version: 1.0 Message-Id: <20221025080230.C01D613A64@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, 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: 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" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747645911963171788?= X-GMAIL-MSGID: =?utf-8?q?1747645911963171788?= niter analysis, specifically the part trying to simplify the computed maybe_zero condition against the loop header copying condition, is confused by us now simplifying _15 = n_8(D) * 4; if (_15 > 0) to _15 = n_8(D) * 4; if (n_8(D) > 0) which is perfectly sound at the point we do this transform. One solution might be to involve ranger in this simplification, another is to be more aggressive when expanding expressions - the condition we try to simplify is _15 > 0, so all we need is expanding that to n_8(D) * 4 > 0. The following does just that. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/100756 * tree-ssa-loop-niter.cc (expand_simple_operations): Also expand multiplications by invariants. * gcc.dg/vect/pr100756.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr100756.c | 15 +++++++++++++++ gcc/tree-ssa-loop-niter.cc | 1 + 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/vect/pr100756.c diff --git a/gcc/testsuite/gcc.dg/vect/pr100756.c b/gcc/testsuite/gcc.dg/vect/pr100756.c new file mode 100644 index 00000000000..c1362f29ebe --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr100756.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_int } */ + +int +foo (int * restrict a, int n) +{ + int i, result = 0; + + a = __builtin_assume_aligned (a, __BIGGEST_ALIGNMENT__); + for (i = 0; i < n * 4; i++) + result += a[i]; + return result; +} + +/* { dg-final { scan-tree-dump-not "epilog loop required" "vect" } } */ diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index 1e0f609d8b6..4ffcef4f4ff 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -2216,6 +2216,7 @@ expand_simple_operations (tree expr, tree stop, hash_map &cache) case PLUS_EXPR: case MINUS_EXPR: + case MULT_EXPR: if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (expr)) && TYPE_OVERFLOW_TRAPS (TREE_TYPE (expr))) return expr;