Hi, The attached patch fixes PR 65163. Although the problem started to show up on trunk and not on the 4.8 / 4.9 branches, I've also backported it, since it's a latent bug.
Tested on trunk with make -k check RUNTESTFLAGS="--target_board=sh-sim \{-m2/-ml,-m2/-mb,-m2a/-mb,-m4/-ml,-m4/-mb,-m4a/-ml,-m4a/-mb}" and on the branches briefly with make -k check-gcc RUNTESTFLAGS="sh.exp --target_board=sh-sim \{-m2/-ml,-m2/-mb,-m2a/-mb,-m4/-ml,-m4/-mb,-m4a/-ml,-m4a/-mb}" Committed as r220916 (trunk), r220917 (4.9), r220918 (4.8). Cheers, Oleg gcc/ChangeLog: PR target/65163 * config/sh/sh.md (swapbsi2, related peephole2): Use const_int -65536 instead of const_int 4294901760. gcc/testsuite/ChangeLog: PR target/65163 * gcc.c-torture/compile/pr65163.c: New.
Index: gcc/config/sh/sh.md =================================================================== --- gcc/config/sh/sh.md (revision 220892) +++ gcc/config/sh/sh.md (working copy) @@ -6218,7 +6218,7 @@ (define_insn "swapbsi2" [(set (match_operand:SI 0 "arith_reg_dest" "=r") (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "r") - (const_int 4294901760)) + (const_int -65536)) ;; 0xFFFF0000 (ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8)) (const_int 65280)) (and:SI (ashiftrt:SI (match_dup 1) (const_int 8)) @@ -6286,7 +6286,7 @@ (define_peephole2 [(set (match_operand:SI 0 "arith_reg_dest" "") (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "") - (const_int 4294901760)) + (const_int -65536)) ;; 0xFFFF0000 (ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8)) (const_int 65280)) (and:SI (ashiftrt:SI (match_dup 1) (const_int 8)) @@ -6296,7 +6296,7 @@ "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])" [(set (match_dup 2) (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "") - (const_int 4294901760)) + (const_int -65536)) ;; 0xFFFF0000 (ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8)) (const_int 65280)) (and:SI (ashiftrt:SI (match_dup 1) (const_int 8)) Index: gcc/testsuite/gcc.c-torture/compile/pr65163.c =================================================================== --- gcc/testsuite/gcc.c-torture/compile/pr65163.c (revision 0) +++ gcc/testsuite/gcc.c-torture/compile/pr65163.c (revision 0) @@ -0,0 +1,22 @@ +/* PR target/65163 */ + +typedef unsigned int uint32_t; +typedef unsigned short uint16_t; +union unaligned_32 { uint32_t l; } __attribute__((packed)); +union unaligned_16 { uint16_t l; } __attribute__((packed)); + +int +test_00 (unsigned char* buf, int bits_per_component) +{ + (((union unaligned_32*)(buf))->l) = + __builtin_bswap32 (bits_per_component == 10 ? 1 : 0); + return 0; +} + +int +test_01 (unsigned char* buf, int bits_per_component) +{ + (((union unaligned_16*)(buf))->l) = + __builtin_bswap16 (bits_per_component == 10 ? 1 : 0); + return 0; +}