Hi Richard,
I'm happy to check-in this regression fix (now known as PR target/128046)
without any new test cases, or more accurately I'm happy to leave the
subtle intricacies of the gcc.target/arm testsuite to the experts.  I suspect
this is also why there are currently/previously no bfi tests (so no advance
warning when things broke).

As mentioned below, rev16_4.c is a minor tweak to the pre-existing rev16_2.c.
Presumably, that test is already broken, and something an arm backend maintainer
needs to address.

It would be a shame for this regression to persist, just because of the
difficulty in writing a portable test case.  It's also blocking a fix for
PR target/128058 on aarch64.

Best regards,
Roger
--

> -----Original Message-----
> From: Richard Earnshaw (foss) <[email protected]>
> Sent: 28 October 2026 17:27
> To: Roger Sayle <[email protected]>; 'Patches GCC' <gcc-
> [email protected]>
> Subject: Re: [ARM PATCH] Ensure the ARM backend is any-or-plus (AOP) safe.
> 
> On 29/09/2026 18:06, Roger Sayle wrote:
> >
> > This patch tweaks arm.md to ensure that it is AOP-safe, i.e. can
> > recognize bfi and rev16 instructions when expressed in RTL using
> > either PLUS, IOR or XOR.  The new test cases confirm this behaviour.
> > The tree-level optimizers currently canonicalize expressions to use
> > IOR_EXPR, but the changes below ensure things will continue to work
> > should this change, and also catch alternate representations (potentially)
> discovered by combine.
> >
> > Updating aarch_rev16_p is a pre-requisite to making aarch64 AOP-safe,
> > which in turn is a pre-requisite to fixing PR tree-optimization/108477.
> >
> > The new rev16_{3,4}.c testcases are clones of rev16_{1,2}.c checking
> > that ^ and + produce the same output/results as |.
> >
> > This patch has been tested on arm-linux-gnueabihf with make bootstrap
> > and make -k check with no new failures.  OK for mainline?
> >
> >
> > 2026-09-29  Roger Sayle  <[email protected]>
> >
> > gcc/ChangeLog
> >         * config/arm/aarch-common.cc (aarch_rev16-p): Allow the rev16
> >         pattern to be expressed as either IOR, XOR or PLUS.
> >         * config/arm/arm/arm.cc (arm_bfi_1_p): Allow the bfi pattern
> >         to be expressed as either IOR, XOR or PLUS.
> >         (arm_rtx_costs_internal) <case XOR>: Treat like IOR, so that
> >         bfi and rev16 instructions are correctly costed when expressed
> >         using XOR.
> >         * config/arm/arm.md (*bfi): Use new ANYORPLUS code iterator.
> >         (*bfi_alt1): Likewise.
> >         (*bfi_alt2): Likewise.
> >         (*bfi_alt3): Likewise.
> >         (arm_rev16si2_alt1): Use new ANYORPLUS code iterator.  Use
> >         aop_pref_ior prefix so that gen_insn constructs the IOR form.
> >         (*arm_rev6si2_alt2): Use new ANYORPLUS code iterator.
> >         * config/arm/iterators.md (ANYORPLUS): New code iterator.
> >         (aop_pref_ior): New code attribute to produce "*" for XOR/PLUS.
> >
> > gcc/testsuite/ChangeLog
> >         * gcc.target/arm/bfi.c: New test case.
> >         * gcc.target/arm/rev16_3.c: Likewise.
> >         * gcc.target/arm/rev16_4.c: Likewise.
> >
> >
> > Thanks in advance,
> > Roger
> > --
> 
> +++ b/gcc/testsuite/gcc.target/arm/bfi.c
> @@ -0,0 +1,19 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -march=armv6t2" } */
> +
> 
> This will fail if the compiler is configured with a hard-float abi and 'auto' 
> for the
> floating-point selection (-mfpu=auto).  It will likely also cause problems if 
> the user
> is running the tests with -mcpu=... as you'll then get an architecture and CPU
> mismatch warning.  The correct way to handle this is to add
> 
> /* { dg-options "-O2" }  */
> /* { dg-require-effective-target arm_arch_v6t2_ok }  */
> /* { dg-add-options arm_arch_v6t2 }  */
> 
> +++ b/gcc/testsuite/gcc.target/arm/rev16_4.c
> ...
> +/* { dg-final { scan-assembler-times {rev16\tr[0-9]+, r[0-9]+} 4 {
> +xfail arm_thumb1_ok } } } */
> 
> XFAILing for thumb1 isn't sufficient - this test will fail for any 
> architecture that
> pre-dates v6t2 and the introduction of the rev16 instruction.
> 
> R.

Reply via email to