public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "olegendo at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/65162] [10/11/12/13/14 Regression][SH] Redundant tests when storing bswapped T bit result in unaligned mem
Date: Fri, 07 Jul 2023 06:38:38 +0000	[thread overview]
Message-ID: <bug-65162-4-uoOUJkdUrG@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-65162-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #13 from Oleg Endo <olegendo at gcc dot gnu.org> ---
(In reply to Oleg Endo from comment #1)
> (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
> 

It's pretty much what GCC 13 produces (with -mlra -ml)

        mov     r5,r0           ! 51    [c=4 l=2]  movsi_i/1
        cmp/eq  #10,r0          ! 48    [c=4 l=2]  cmpeqsi_t/1
        movt    r0              ! 49    [c=4 l=2]  movt
        mov     #0,r1           ! 11    [c=4 l=2]  movsi_i/2
        mov.b   r0,@(1,r4)      ! 29    [c=4 l=2]  *movqi_store_mem_disp04/0
        mov     #0,r0           ! 34    [c=4 l=2]  movsi_i/2
        rts                     ! 55    [c=0 l=2]  *return_i
        mov.b   r1,@r4          ! 18    [c=4 l=2]  *movqi/5

  parent reply	other threads:[~2023-07-07  6:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-22 12:21 [Bug target/65162] New: [5 " olegendo at gcc dot gnu.org
2015-02-22 13:04 ` [Bug target/65162] " olegendo at gcc dot gnu.org
2015-02-23 10:18 ` rguenth at gcc dot gnu.org
2015-04-22 11:57 ` [Bug target/65162] [5/6 " jakub at gcc dot gnu.org
2015-07-16  9:11 ` rguenth at gcc dot gnu.org
2021-05-14  9:47 ` [Bug target/65162] [9/10/11/12 " jakub at gcc dot gnu.org
2021-06-01  8:06 ` rguenth at gcc dot gnu.org
2022-05-27  9:35 ` [Bug target/65162] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:31 ` jakub at gcc dot gnu.org
2023-07-07  6:38 ` olegendo at gcc dot gnu.org [this message]
2023-07-07 10:30 ` [Bug target/65162] [11/12/13/14 " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-65162-4-uoOUJkdUrG@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).