ifcvt: reject use of ctrap post reload [PR 105192]

Message ID 20260408152354.77017-1-xry111@xry111.site
State New
Headers
Series ifcvt: reject use of ctrap post reload [PR 105192] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply

Commit Message

Xi Ruoyao April 8, 2026, 3:23 p.m. UTC
  The ctrap expanders of several targets can end up creating pseudos.  And
it would be really counter-intuitive to disallow a define_expand to
generate pseudos.  So don't invoke the expander post reload.

	PR target/105192

gcc/

	* ifcvt.cc (find_if_header): Don't attempt to use ctrap expander
	after reload.

gcc/testsuite/

	* gcc.c-torture/compile/pr105192.c: New test.
---

Bootstrapped and regtested on x86_64-linux-gnu and
mips64el-linux-gnuabi64.  Ok for trunk?

 gcc/ifcvt.cc                                   | 2 +-
 gcc/testsuite/gcc.c-torture/compile/pr105192.c | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr105192.c
  

Comments

Andrew Pinski April 8, 2026, 7:01 p.m. UTC | #1
On Wed, Apr 8, 2026 at 8:24 AM Xi Ruoyao <xry111@xry111.site> wrote:
>
> The ctrap expanders of several targets can end up creating pseudos.  And
> it would be really counter-intuitive to disallow a define_expand to
> generate pseudos.  So don't invoke the expander post reload.
>
>         PR target/105192
>
> gcc/
>
>         * ifcvt.cc (find_if_header): Don't attempt to use ctrap expander
>         after reload.

Ok for all branches. There is maybe a small missed optimization for
some targets after this patch but I think that is ok.

Thanks,
Andrew

>
> gcc/testsuite/
>
>         * gcc.c-torture/compile/pr105192.c: New test.
> ---
>
> Bootstrapped and regtested on x86_64-linux-gnu and
> mips64el-linux-gnuabi64.  Ok for trunk?
>
>  gcc/ifcvt.cc                                   | 2 +-
>  gcc/testsuite/gcc.c-torture/compile/pr105192.c | 9 +++++++++
>  2 files changed, 10 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr105192.c
>
> diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc
> index 7f5af2ca915..c151146c1b2 100644
> --- a/gcc/ifcvt.cc
> +++ b/gcc/ifcvt.cc
> @@ -5180,7 +5180,7 @@ find_if_header (basic_block test_bb, int pass)
>        && cond_exec_find_if_block (&ce_info))
>      goto success;
>
> -  if (targetm.have_trap ()
> +  if (!reload_completed && targetm.have_trap ()
>        && optab_handler (ctrap_optab, word_mode) != CODE_FOR_nothing
>        && find_cond_trap (test_bb, then_edge, else_edge))
>      goto success;
> diff --git a/gcc/testsuite/gcc.c-torture/compile/pr105192.c b/gcc/testsuite/gcc.c-torture/compile/pr105192.c
> new file mode 100644
> index 00000000000..0cc61505218
> --- /dev/null
> +++ b/gcc/testsuite/gcc.c-torture/compile/pr105192.c
> @@ -0,0 +1,9 @@
> +/* { dg-additional-options "-fno-if-conversion -fharden-compares" } */
> +
> +int a, b;
> +
> +void
> +foo (void)
> +{
> +  b = a % 0 > 0;
> +}
> --
> 2.53.0
>
  

Patch

diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc
index 7f5af2ca915..c151146c1b2 100644
--- a/gcc/ifcvt.cc
+++ b/gcc/ifcvt.cc
@@ -5180,7 +5180,7 @@  find_if_header (basic_block test_bb, int pass)
       && cond_exec_find_if_block (&ce_info))
     goto success;
 
-  if (targetm.have_trap ()
+  if (!reload_completed && targetm.have_trap ()
       && optab_handler (ctrap_optab, word_mode) != CODE_FOR_nothing
       && find_cond_trap (test_bb, then_edge, else_edge))
     goto success;
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr105192.c b/gcc/testsuite/gcc.c-torture/compile/pr105192.c
new file mode 100644
index 00000000000..0cc61505218
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr105192.c
@@ -0,0 +1,9 @@ 
+/* { dg-additional-options "-fno-if-conversion -fharden-compares" } */
+
+int a, b;
+
+void
+foo (void)
+{
+  b = a % 0 > 0;
+}