From: Torbjörn SVENSSON <[email protected]>

The Armv8.1-M profitability hook rejects sequences other than the
recognized conditional arithmetic and VSEL patterns, even when the
conversion has removed the conditional entirely.

There is no need to reject a sequence once the conditional is gone,
so use the usual profitability checks in that case. Leave the
PR116444 restriction in place when IF_THEN_ELSE remains.

For armv8.1-m.main, the generated code for gcc.target/arm/epilog-1.c
changes from

        push    {r3, r4, r5, lr}
        ldr     r4, .L5
        ldr     r5, [r4]
        tst     r5, #4
        csinc   r2, r2, r2, eq
        bl      bar
        movs    r0, #0
        pop     {r3, r4, r5, pc}

to

        push    {r4, lr}
        ldr     r4, .L5
        ldr     r4, [r4]
        ubfx    r4, r4, #2, #1
        add     r2, r2, r4
        bl      bar
        movs    r0, #0
        pop     {r4, pc}

        PR target/122965

gcc/ChangeLog:

        * config/arm/arm.cc (arm_noce_conversion_profitable_p): Use
        default profitability checks for unconditional sequences.

gcc/testsuite/ChangeLog:

        * gcc.target/arm/epilog-1.c: Expect UBFX and ADD for
        armv8.1-m.main.

Signed-off-by: Torbjörn SVENSSON <[email protected]>
---
Following Richard’s suggestion in 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122965#c2, this patch updates 
arm_noce_conversion_profitable_p to use the default cost metric when the 
proposed sequence no longer contains an IF_THEN_ELSE.

Regression tested on arm-none-eabi with r17-5743-ge33129b871c302 as the 
baseline.

OK for trunk and releases/gcc-16?

--



This is a forge pull request published on the gcc-patches mailing list mailing 
list
as requested by Torbjörn Svensson via Sourceware Forge 
<[email protected]>.
Forge discussion: https://forge.sourceware.org/gcc/gcc/pulls/265

Get it locally using:
```
git fetch forge-upstream "+refs/versioned_pull/265/*:refs/versioned_pull/265/*"
git switch -c "pr-265-v1" "refs/versioned_pull/265/1/head"
```
Or, download the patch at: https://forge.sourceware.org/gcc/gcc/pulls/265.diff
Created on: 2026-11-02 16:15:50+00:00
Latest update: 2026-11-02 16:25:44+00:00
Changes: 2 changed files, 16 additions, 3 deletions
Head revision: azoff/gcc ref pr/bics commit 
d89cabcbec6c11dbb3e7dbf0081e665719cf3375 
Base revision: gcc/gcc ref trunk commit 
e33129b871c30276acfaed2b435ae5b505b73655 r17-5743-ge33129b871c302
Merge base: e33129b871c30276acfaed2b435ae5b505b73655
Requested Reviewers: rearnsha

Changed files:
- M: gcc/config/arm/arm.cc
- M: gcc/testsuite/gcc.target/arm/epilog-1.c

 gcc/config/arm/arm.cc                   | 15 ++++++++++++++-
 gcc/testsuite/gcc.target/arm/epilog-1.c |  4 ++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index 940c689b21e0e..7bea1805e8853 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -35116,7 +35116,20 @@ arm_noce_conversion_profitable_p (rtx_insn *seq, 
struct noce_if_info *if_info)
   if (arm_is_vsel_fp_insn (seq))
     return true;
 
-  return false;
+  /* Keep the PR116444 restriction for conditional sequences, but use
+     normal profitability checks when the conditional has disappeared.  */
+  subrtx_iterator::array_type array;
+  for (rtx_insn *insn = seq; insn; insn = NEXT_INSN (insn))
+    {
+      if (!NONDEBUG_INSN_P (insn))
+       continue;
+
+      FOR_EACH_SUBRTX (iter, array, PATTERN (insn), ALL)
+       if (GET_CODE (*iter) == IF_THEN_ELSE)
+         return false;
+    }
+
+  return default_noce_conversion_profitable_p (seq, if_info);
 }
 
 /* Output assembly to read the thread pointer from the appropriate TPIDR
diff --git a/gcc/testsuite/gcc.target/arm/epilog-1.c 
b/gcc/testsuite/gcc.target/arm/epilog-1.c
index 70aa12c63ff64..86e7abfc79ae3 100644
--- a/gcc/testsuite/gcc.target/arm/epilog-1.c
+++ b/gcc/testsuite/gcc.target/arm/epilog-1.c
@@ -20,8 +20,8 @@ Below block is for non-armv8.1-m.main
 ** |
 
 Below block is for armv8.1-m.main
-**     tst     r[0-9]+, #4
-**     csinc   r2, r2, r2, eq
+**     ubfx    (r[0-9]+), r[0-9]+, #2, #1
+**     add     r2, r2, \1
 
 ** )
 **     bl      bar
-- 
2.56.0

Reply via email to