[Bug target/65162] [5 Regression][SH] Redundant tests when storing bswapped T bit result in unaligned mem

olegendo at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Feb 22 13:04:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65162

Oleg Endo <olegendo at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-02-22
     Ever confirmed|0                           |1

--- Comment #1 from Oleg Endo <olegendo at gcc dot gnu.org> ---
(In reply to Oleg Endo from comment #0)
> The following example is taken from libav, which contains quite some uses of
> this code pattern.
> 
> typedef unsigned short int uint16_t;
> union unaligned_16 { uint16_t l; } __attribute__((packed));
> 
> int
> test (unsigned char* buf, int bits_per_component)
> {
>   (((union unaligned_16 *)(buf))->l) =
>     __builtin_bswap16 (bits_per_component == 10 ? 1 : 0);
> 
>   return 0;
> }
> 

BTW, it should actually translate to something like:

    mov    r6,r0
    cmp/eq    #10,r0
    movt    r0
    mov.b    r0,@(1,r4)
    mov    #0,r0
    rts
    mov.b    r0,@r4

or
    mov    r6,r0
    cmp/eq    #10,r0
    movt    r0
    mov.b    r0,@(1,r4)
    shlr8   r0
    rts
    mov.b    r0,@r4



More information about the Gcc-bugs mailing list