namaskaaram A fix for PR103383 is attached along with a test case. The fix has been part of Xilinx/AMD gcc repository for many years. This patch adds a test case.
Build and Test Process: Toolset : microblazeel-amd-elf Test : gcc regression Execution Vehicle: qemu-system-microblazeel No regressions were found.
From 07fef4c6063fdf6a4c69c169ee16ccf9965d18fe Mon Sep 17 00:00:00 2001 From: Gopi Kumar Bulusu <[email protected]> Date: Thu, 2 Apr 2026 12:02:59 +0530 Subject: [PATCH] [MicroBlaze] [PR target/103383] Fix __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. Files Added/Modified gcc/ * config/microblaze/microblaze.md: bswaphi2: (set_attr length 8) gcc/testsuite * gcc.target/microblaze/isa/pr103383.c: New test. Signed-off-by: Nagaraju Mekala <[email protected]> Signed-off-by: Gopi Kumar Bulusu <[email protected]> --- gcc/config/microblaze/microblaze.md | 6 ++++++ .../gcc.target/microblaze/isa/pr103383.c | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/gcc.target/microblaze/isa/pr103383.c diff --git a/gcc/config/microblaze/microblaze.md b/gcc/config/microblaze/microblaze.md index 7d60c6ca3b2..906d4572dc0 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 00000000000..ab6fd4b6885 --- /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; +} + + -- 2.47.3
