From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1984) id 47A58385E45A; Wed, 14 Feb 2024 16:14:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47A58385E45A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707927252; bh=eOJkCka6km8FuDIxNEBV4IAPYTxqwGIVadE3kmyeF+s=; h=From:To:Subject:Date:From; b=X3/dzH8XeUFi7LXTvchkIN7/QAOle99o3lZS9avN/V0qD5EGE4YdG1Fpj+xDboYy+ oJpg3D2mHQ+xB+CmnAwY4AFa4cClkWK+Ew7R59+vZsbkAGwdDReKew2wHyFv6G9fJv q6jdpU9zPfLvyqHh6lMqh2PobaivcYuyLsl+ZaWY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Tamar Christina To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8984] middle-end: inspect all exits for additional annotations for loop. X-Act-Checkin: gcc X-Git-Author: Tamar Christina X-Git-Refname: refs/heads/master X-Git-Oldrev: b79d3e6a9284703b70688122f7d4955e7c50804a X-Git-Newrev: 16ae5efedd389e8952f35bb10665518c22a9251c Message-Id: <20240214161412.47A58385E45A@sourceware.org> Date: Wed, 14 Feb 2024 16:14:12 +0000 (GMT) List-Id: https://gcc.gnu.org/g:16ae5efedd389e8952f35bb10665518c22a9251c commit r14-8984-g16ae5efedd389e8952f35bb10665518c22a9251c Author: Tamar Christina Date: Wed Feb 14 16:13:51 2024 +0000 middle-end: inspect all exits for additional annotations for loop. Attaching a pragma to a loop which has a complex condition often gets the pragma dropped. e.g. #pragma GCC novector while (i < N && parse_tables_n--) before lowering this is represented as: if (ANNOTATE_EXPR ) ... But after lowering the condition is broken appart and attached to the final component of the expression: if (parse_tables_n.2_2 != 0) goto ; else goto ; : iftmp.1D.4452 = 1; goto ; : iftmp.1D.4452 = 0; : D.4451 = .ANNOTATE (iftmp.1D.4452, 2, 0); if (D.4451 != 0) goto ; else goto ; : and it's never heard from again because during replace_loop_annotate we only inspect the loop header and latch for annotations. Since annotations were supposed to apply to the loop as a whole this fixes it by checking the loop exit src blocks for annotations instead. gcc/ChangeLog: * tree-cfg.cc (replace_loop_annotate): Inspect loop edges for annotations. gcc/testsuite/ChangeLog: * gcc.dg/vect/vect-novect_gcond.c: New test. Diff: --- gcc/testsuite/gcc.dg/vect/vect-novect_gcond.c | 39 +++++++++++++++++++++++++++ gcc/tree-cfg.cc | 9 +++---- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/gcc.dg/vect/vect-novect_gcond.c b/gcc/testsuite/gcc.dg/vect/vect-novect_gcond.c new file mode 100644 index 000000000000..01e69cbef9d5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-novect_gcond.c @@ -0,0 +1,39 @@ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break_hw } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-O3" } */ + +/* { dg-final { scan-tree-dump-not "LOOP VECTORIZED" "vect" } } */ + +#include "tree-vect.h" + +#define N 306 +#define NEEDLE 136 + +int table[N]; + +__attribute__ ((noipa)) +int foo (int i, unsigned short parse_tables_n) +{ + parse_tables_n >>= 9; + parse_tables_n += 11; +#pragma GCC novector + while (i < N && parse_tables_n--) + table[i++] = 0; + + return table[NEEDLE]; +} + +int main () +{ + check_vect (); + +#pragma GCC novector + for (int j = 0; j < N; j++) + table[j] = -1; + + if (foo (0, 0xFFFF) != 0) + __builtin_abort (); + + return 0; +} diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index cdd439fe7506..bdffc3b4ed27 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -320,12 +320,9 @@ replace_loop_annotate (void) for (auto loop : loops_list (cfun, 0)) { - /* First look into the header. */ - replace_loop_annotate_in_block (loop->header, loop); - - /* Then look into the latch, if any. */ - if (loop->latch) - replace_loop_annotate_in_block (loop->latch, loop); + /* Check all exit source blocks for annotations. */ + for (auto e : get_loop_exit_edges (loop)) + replace_loop_annotate_in_block (e->src, loop); /* Push the global flag_finite_loops state down to individual loops. */ loop->finite_p = flag_finite_loops;