https://gcc.gnu.org/g:474bce3d2ddb6417e7acad84bbad7524018de4e4
commit r15-11175-g474bce3d2ddb6417e7acad84bbad7524018de4e4 Author: Gopi Kumar Bulusu <[email protected]> Date: Thu Apr 2 12:02:59 2026 +0530 Fix incorrect length for __builtin_bswap16 The bswaphi pattern generates 2 assembly instructions with a length of 8 bytes. The bswaphi pattern missed the length attribute, as a result the default of 8 bytes was assumed. This allowed the "8 byte" bswaphi pattern to be scheduled into the delay slot of a branch instruction where only a 4 byte instruction can be placed. This patch addresses the problem. Add trunk commit to release/gcc-15 branch. 2026-05-16 Michael Eager <[email protected]> gcc/ChangeLog: PR target/103383 * config/microblaze/microblaze.md: bswaphi2: (set_attr length 8) gcc/testsuite/ChangeLog: PR target/103383 * gcc.target/microblaze/isa/pr103383.c: New test. Signed-off-by: Nagaraju Mekala <[email protected]> Signed-off-by: Gopi Kumar Bulusu <[email protected]> Signed-off-by: Michael J. Eager <[email protected]> Diff: --- gcc/config/microblaze/microblaze.md | 6 ++++++ gcc/testsuite/gcc.target/microblaze/isa/pr103383.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/gcc/config/microblaze/microblaze.md b/gcc/config/microblaze/microblaze.md index 270df8da0c50..9b2711f3b23c 100644 --- a/gcc/config/microblaze/microblaze.md +++ b/gcc/config/microblaze/microblaze.md @@ -369,6 +369,9 @@ (bswap:SI (match_operand:SI 1 "register_operand" "r")))] "TARGET_REORDER" "swapb %0, %1" + [(set_attr "type" "no_delay_arith") + (set_attr "mode" "SI") + (set_attr "length" "4")] ) (define_insn "bswaphi2" @@ -377,6 +380,9 @@ "TARGET_REORDER" "swapb %0, %1 swaph %0, %0" + [(set_attr "type" "no_delay_arith") + (set_attr "mode" "SI") + (set_attr "length" "8")] ) ;;---------------------------------------------------------------- diff --git a/gcc/testsuite/gcc.target/microblaze/isa/pr103383.c b/gcc/testsuite/gcc.target/microblaze/isa/pr103383.c new file mode 100644 index 000000000000..ab6fd4b6885e --- /dev/null +++ b/gcc/testsuite/gcc.target/microblaze/isa/pr103383.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mcpu=v10.0 -mxl-barrel-shift -S" } */ + +unsigned short t = 0x1234; + +extern unsigned short int g(); + +int f() +{ + unsigned short s = t; + +/* { dg-final { scan-assembler-not "brlid\tr(\[0-9]\|\[1-2]\[0-9]\|3\[0-1]),g\n\[ \t\n\]*swap" } } */ + if (__builtin_bswap16(s) != g()) { + return -1; + } + + return 0; +} + +
