Skip to content

Commit 9e3e6ce

Browse files
Gopi Kumar Bulusueagerm
authored andcommitted
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. 2026-04-18 Michael Eager <eager@eagercon.com> 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 <nmekala@xilix.com> Signed-off-by: Gopi Kumar Bulusu <gopi@sankhya.com> Signed-off-by: Michael J. Eager <eager@eagercon.com>
1 parent 439467e commit 9e3e6ce

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

gcc/config/microblaze/microblaze.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@
369369
(bswap:SI (match_operand:SI 1 "register_operand" "r")))]
370370
"TARGET_REORDER"
371371
"swapb %0, %1"
372+
[(set_attr "type" "no_delay_arith")
373+
(set_attr "mode" "SI")
374+
(set_attr "length" "4")]
372375
)
373376

374377
(define_insn "bswaphi2"
@@ -377,6 +380,9 @@
377380
"TARGET_REORDER"
378381
"swapb %0, %1
379382
swaph %0, %0"
383+
[(set_attr "type" "no_delay_arith")
384+
(set_attr "mode" "SI")
385+
(set_attr "length" "8")]
380386
)
381387

382388
;;----------------------------------------------------------------
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2 -mcpu=v10.0 -mxl-barrel-shift -S" } */
3+
4+
unsigned short t = 0x1234;
5+
6+
extern unsigned short int g();
7+
8+
int f()
9+
{
10+
unsigned short s = t;
11+
12+
/* { dg-final { scan-assembler-not "brlid\tr(\[0-9]\|\[1-2]\[0-9]\|3\[0-1]),g\n\[ \t\n\]*swap" } } */
13+
if (__builtin_bswap16(s) != g()) {
14+
return -1;
15+
}
16+
17+
return 0;
18+
}
19+
20+

0 commit comments

Comments
 (0)