From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id CD3923857BB6; Tue, 25 Oct 2022 08:03:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD3923857BB6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666684994; bh=s1r83rMqB8fltc+79f/ox2NEazwXSYJwRxndPANRNG0=; h=From:To:Subject:Date:From; b=jyKU+uY49R2wWHuXNJQiy2HhFeOx3wSFfn2MeQ0Q/91duMxPBr0+Xa+sdKp/ujpMG 10mOjyLOmxIlVrfte5HvBJW4yW5xT6MKBlLk+l9azSVj12R/8s0AOaviNRyw5EJ3UZ 1UL7rR4s/QUYaRSgYx6GlK1aUqLT0UqcZmJmGBqE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3476] tree-optimization/100756 - niter analysis and folding X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 321f89e58510dd5df1b3dbe323344b987a7b11c6 X-Git-Newrev: 19295e8607da2f743368fe6f5708146616aafa91 Message-Id: <20221025080314.CD3923857BB6@sourceware.org> Date: Tue, 25 Oct 2022 08:03:14 +0000 (GMT) List-Id: https://gcc.gnu.org/g:19295e8607da2f743368fe6f5708146616aafa91 commit r13-3476-g19295e8607da2f743368fe6f5708146616aafa91 Author: Richard Biener Date: Mon Oct 24 09:51:32 2022 +0200 tree-optimization/100756 - niter analysis and folding 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. PR tree-optimization/100756 * tree-ssa-loop-niter.cc (expand_simple_operations): Also expand multiplications by invariants. * gcc.dg/vect/pr100756.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/vect/pr100756.c | 15 +++++++++++++++ gcc/tree-ssa-loop-niter.cc | 1 + 2 files changed, 16 insertions(+) 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;