From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 114743857735; Tue, 2 May 2023 20:12:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 114743857735 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683058354; bh=WU1eqn17Hc96eJ0tNkBh9AgHKI/I0RLCEeHP9SRdV0o=; h=From:To:Subject:Date:From; b=GbMJiCAFg+sGeLd0Ktk0fp5STzjC6amtBZT8uQomCJcNALwvIsYcfLhoLv6JV8lnD vKpGJnfkhUQ1JaUxMgymXz/sGIKQfBps2OuEIFEqtwyHapxMxyj9TNdj8UluSpUZjf mg0wBdhiQWahuIHVhfiXGgaQAjinrod0dtnOcetg= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10687] ivopts: Fix IP_END handling for asm goto [PR107997] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: f187d4c17546df91c3b6b9c0912403d14c6eb3c8 X-Git-Newrev: 5a0fd69bb3aa1709f0bea5d6b91fb30ca226c1ed Message-Id: <20230502201234.114743857735@sourceware.org> Date: Tue, 2 May 2023 20:12:34 +0000 (GMT) List-Id: https://gcc.gnu.org/g:5a0fd69bb3aa1709f0bea5d6b91fb30ca226c1ed commit r11-10687-g5a0fd69bb3aa1709f0bea5d6b91fb30ca226c1ed Author: Jakub Jelinek Date: Sat Dec 10 16:50:39 2022 +0100 ivopts: Fix IP_END handling for asm goto [PR107997] The following testcase ICEs, because the latch bb ends with asm goto which has both fallthrough to the header and one or more labels in the header too. In that case there is just a single edge out of the latch block, but still the asm goto is stmt_ends_bb_p statement, yet ivopts decides to emit an IV bump at the IP_END position and inserts it into the same bb as the asm goto after it, which then fails verification (control flow in the middle of bb). The following patch fixes it by splitting the latch -> header edge in that case and inserting into the newly created bb, where split_edge -> redirect_edge_and_branch is able to deal with this case correctly. 2022-12-10 Jakub Jelinek PR tree-optimization/107997 * tree-ssa-loop-ivopts.c: Include cfganal.h. (create_new_iv) : If ip_end_pos bb is non-empty and ends with a stmt which ends bb, instead of adding iv update after it split the latch edge and insert iterator into the new latch bb. * gcc.c-torture/compile/pr107997.c: New test. (cherry picked from commit 7676235f690e624b7ed41a22b22ce8ccfac1492f) Diff: --- gcc/testsuite/gcc.c-torture/compile/pr107997.c | 23 +++++++++++++++++++++++ gcc/tree-ssa-loop-ivopts.c | 7 +++++++ 2 files changed, 30 insertions(+) diff --git a/gcc/testsuite/gcc.c-torture/compile/pr107997.c b/gcc/testsuite/gcc.c-torture/compile/pr107997.c new file mode 100644 index 00000000000..89e1fd349c3 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr107997.c @@ -0,0 +1,23 @@ +/* PR tree-optimization/107997 */ + +int a, b; +void bar (int); +int baz (void); + +void * +foo (int x, void *y) +{ + asm goto ("" : : "r" (x || !a) : : l); +l: + if (y) + return 0; + bar (b ? b : x); + while (x--) + { + if (!baz ()) + baz (); + asm goto ("" : : : : l2); + l2:; + } + return y; +} diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 913b3ad4258..459f0280cdc 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -131,6 +131,7 @@ along with GCC; see the file COPYING3. If not see #include "builtins.h" #include "tree-vectorizer.h" #include "dbgcnt.h" +#include "cfganal.h" /* For lang_hooks.types.type_for_mode. */ #include "langhooks.h" @@ -7109,6 +7110,12 @@ create_new_iv (struct ivopts_data *data, struct iv_cand *cand) case IP_END: incr_pos = gsi_last_bb (ip_end_pos (data->current_loop)); after = true; + if (!gsi_end_p (incr_pos) && stmt_ends_bb_p (gsi_stmt (incr_pos))) + { + edge e = find_edge (gsi_bb (incr_pos), data->current_loop->header); + incr_pos = gsi_after_labels (split_edge (e)); + after = false; + } break; case IP_AFTER_USE: