* hardcmp: split before dispatch edge
@ 2022-03-24 1:42 Alexandre Oliva
2022-03-24 7:28 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Alexandre Oliva @ 2022-03-24 1:42 UTC (permalink / raw)
To: gcc-patches
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.
Regstrapped on x86_64-linux-gnu. Ok to install?
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.
---
gcc/gimple-harden-conditionals.cc | 12 +++++++++---
gcc/testsuite/gcc.dg/pr104975.c | 20 ++++++++++++++++++++
2 files changed, 29 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr104975.c
diff --git a/gcc/gimple-harden-conditionals.cc b/gcc/gimple-harden-conditionals.cc
index 6a5fc3fb9e1a2..be01f3ea8c44a 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 0000000000000..04532fc444340
--- /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;
+}
--
Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/
Free Software Activist GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts. Ask me about <https://stallmansupport.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: hardcmp: split before dispatch edge
2022-03-24 1:42 hardcmp: split before dispatch edge Alexandre Oliva
@ 2022-03-24 7:28 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-03-24 7:28 UTC (permalink / raw)
To: Alexandre Oliva; +Cc: GCC Patches
On Thu, Mar 24, 2022 at 2:43 AM Alexandre Oliva via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
>
> 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.
>
> Regstrapped on x86_64-linux-gnu. Ok to install?
OK.
>
> 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.
> ---
> gcc/gimple-harden-conditionals.cc | 12 +++++++++---
> gcc/testsuite/gcc.dg/pr104975.c | 20 ++++++++++++++++++++
> 2 files changed, 29 insertions(+), 3 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/pr104975.c
>
> diff --git a/gcc/gimple-harden-conditionals.cc b/gcc/gimple-harden-conditionals.cc
> index 6a5fc3fb9e1a2..be01f3ea8c44a 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 0000000000000..04532fc444340
> --- /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;
> +}
>
>
> --
> Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/
> Free Software Activist GNU Toolchain Engineer
> Disinformation flourishes because many people care deeply about injustice
> but very few check the facts. Ask me about <https://stallmansupport.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-03-24 7:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24 1:42 hardcmp: split before dispatch edge Alexandre Oliva
2022-03-24 7:28 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).