https://gcc.gnu.org/g:c4d53bc3c96770438d63a0d35a638beabad67c65

commit r16-7323-gc4d53bc3c96770438d63a0d35a638beabad67c65
Author: Richard Earnshaw <[email protected]>
Date:   Wed Feb 4 14:14:37 2026 +0000

    compare-elim: arm: enable compare-elimination on Arm [PR123604]
    
    The Arm port has never had the compare elimination pass enabled by
    adding a definition of TARGET_FLAGS_REGNUM.  But just adding this is
    insufficient because the target uses COND_EXEC and compare-elim is not
    yet set up to handle this.
    
    This seems to be quite simple, since we just need to recognize
    COND_EXEC in insns when scanning for uses of the condition code
    register.
    
    This is a partial mitigation for the code quality regression
    reported in PR target/123604.
    
    gcc/ChangeLog:
    
            PR target/123604
            * compare-elim.cc (find_flags_uses_in_insn): Handle COND_EXEC.
            * config/arm/arm.cc (TARGET_FLAGS_REGNUM): Define.

Diff:
---
 gcc/compare-elim.cc   | 2 ++
 gcc/config/arm/arm.cc | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/gcc/compare-elim.cc b/gcc/compare-elim.cc
index 006d4e35efcd..723f9e31c791 100644
--- a/gcc/compare-elim.cc
+++ b/gcc/compare-elim.cc
@@ -258,6 +258,8 @@ find_flags_uses_in_insn (struct comparison *cmp, rtx_insn 
*insn)
          x = SET_SRC (x);
        if (GET_CODE (x) == IF_THEN_ELSE)
          x = XEXP (x, 0);
+       if (GET_CODE (x) == COND_EXEC)
+         x = COND_EXEC_TEST (x);
        if (COMPARISON_P (x)
            && loc == &XEXP (x, 0)
            && XEXP (x, 1) == const0_rtx)
diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index 0a1f6612d07f..ff3400ae0353 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -839,6 +839,9 @@ static const scoped_attribute_specs *const 
arm_attribute_table[] =
 
 #undef TARGET_VECTORIZE_GET_MASK_MODE
 #define TARGET_VECTORIZE_GET_MASK_MODE arm_get_mask_mode
+
+#undef TARGET_FLAGS_REGNUM
+#define TARGET_FLAGS_REGNUM CC_REGNUM
 
 /* Obstack for minipool constant handling.  */
 static struct obstack minipool_obstack;

Reply via email to