From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1666684950; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=u50kouI+EsUb7ZLUHL8kPLAX8pRnmFS+R9JTdckkcrk=; b=lJkkkHxY69HTGwal88usFhTDGW5JyV1QHfk2DQGx3+07WXMsF7Np0KQPFMutHXoTin8fGq Z9FQ409zgCdtI0IfTa7uVexHE31eGrEJ76ZpepXFS4x1+4ltQh+oZYDx1zIa1GlsVxHoez YxC6kJCQRtg3C+QRhGGQjhX1eym3l4M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1666684950; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=u50kouI+EsUb7ZLUHL8kPLAX8pRnmFS+R9JTdckkcrk=; b=a6PhYjITW5/0x6JUNwwg9RhpEjFM7CIka6WG3/z7Is6vrSMZqJlN3qGVag4vfjOl4kz+t7 nUmlZ0XgEHcdMYAQ== 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) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/100756 - niter analysis and folding MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 List-Id: 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; -- 2.35.3