From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id 00CBA3858C2C; Thu, 24 Mar 2022 13:10:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00CBA3858C2C MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7800] hardcmp: split before dispatch edge X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/heads/master X-Git-Oldrev: 11fb784ac592567dbcb7874c27e67ee0feb8fbf0 X-Git-Newrev: b8c4171ebd72079e55aceadbcfc883f517cdf895 Message-Id: <20220324131016.00CBA3858C2C@sourceware.org> Date: Thu, 24 Mar 2022 13:10:16 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Mar 2022 13:10:16 -0000 https://gcc.gnu.org/g:b8c4171ebd72079e55aceadbcfc883f517cdf895 commit r12-7800-gb8c4171ebd72079e55aceadbcfc883f517cdf895 Author: Alexandre Oliva Date: Thu Mar 24 10:02:27 2022 -0300 hardcmp: split before dispatch edge If we harden a compare at the end of a block with an edge to the abnormal dispatch block, it won't have a single successor. Arrange to split the block at its final stmt so as to have a single succ. for gcc/ChangeLog PR middle-end/104975 * gimple-harden-conditionals.cc (pass_harden_compares::execute): Force split in case of multiple edges. for gcc/testsuite/ChangeLog PR middle-end/104975 * gcc.dg/pr104975.c: New. Diff: --- gcc/gimple-harden-conditionals.cc | 12 +++++++++--- gcc/testsuite/gcc.dg/pr104975.c | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/gcc/gimple-harden-conditionals.cc b/gcc/gimple-harden-conditionals.cc index 6a5fc3fb9e1..be01f3ea8c4 100644 --- a/gcc/gimple-harden-conditionals.cc +++ b/gcc/gimple-harden-conditionals.cc @@ -509,10 +509,16 @@ pass_harden_compares::execute (function *fun) gsi_insert_before (&gsi_split, asgnck, GSI_SAME_STMT); /* We wish to insert a cond_expr after the compare, so arrange - for it to be at the end of a block if it isn't. */ - if (!gsi_end_p (gsi_split)) + for it to be at the end of a block if it isn't, and for it + to have a single successor in case there's more than + one, as in PR104975. */ + if (!gsi_end_p (gsi_split) + || !single_succ_p (gsi_bb (gsi_split))) { - gsi_prev (&gsi_split); + if (!gsi_end_p (gsi_split)) + gsi_prev (&gsi_split); + else + gsi_split = gsi_last_bb (gsi_bb (gsi_split)); basic_block obb = gsi_bb (gsi_split); basic_block nbb = split_block (obb, gsi_stmt (gsi_split))->dest; gsi_next (&gsi_split); diff --git a/gcc/testsuite/gcc.dg/pr104975.c b/gcc/testsuite/gcc.dg/pr104975.c new file mode 100644 index 00000000000..04532fc4443 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr104975.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fharden-compares -fno-inline -fno-ipa-pure-const" } */ + +__attribute__ ((pure, returns_twice)) int +bar (int); + +int +quux (void) +{ + return 0; +} + +int +foo (short int x) +{ + x = !x; + bar (quux ()); + + return x; +}