public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/57052] New: missed optimization with rotate and mask
@ 2013-04-24  0:00 amodra at gmail dot com
  2013-04-24  9:13 ` [Bug target/57052] " amodra at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: amodra at gmail dot com @ 2013-04-24  0:00 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57052

             Bug #: 57052
           Summary: missed optimization with rotate and mask
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: amodra@gmail.com


/* -m32 -O -S */
int
foo (unsigned int x, int r)
{
  return ((x << r) | (x >> (32 - r))) & 0xff;
}

results in:

foo:
    rlwnm 3,3,4,0xffffffff
    rlwinm 3,3,0,24,31
    blr

Compiling the same code with -m32 -O -S -mlittle gives the properly optimized
result of:

foo:
    rlwnm 3,3,4,0xff
    blr

This is because many of the rs6000.md rotate/shift and mask patterns use
subregs with wrong byte offsets.  eg. rotlsi3_internal7, the insn that ought to
match here, has (subreg:QI (rotate:SI ...) 0).  The 0 selects the most
significant byte when BYTES_BIG_ENDIAN and the least significant when
!BYTES_BIG_ENDIAN.

Fortunately combine doesn't seem to generate subregs for high parts, so
changing the testcase mask to 0xff000000 doesn't result in wrong code.

Annoyingly, rotlsi3_internal4 would match here too if combine_simplify_rtx()
didn't simplify (set (reg:SI) (and:SI () 255)) to use subregs.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-04-04 15:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-24  0:00 [Bug target/57052] New: missed optimization with rotate and mask amodra at gmail dot com
2013-04-24  9:13 ` [Bug target/57052] " amodra at gmail dot com
2013-04-25  7:57 ` amodra at gmail dot com
2014-03-14 19:36 ` meissner at gcc dot gnu.org
2014-04-04 15:11 ` wschmidt at gcc dot gnu.org

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).