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

            Bug ID: 80131
           Summary: powerpc: 1U << (31 - x) doesn't generate optimised
                    code
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: christophe.le...@c-s.fr
  Target Milestone: ---

I would expect the two functions below to generate the same code,  but it
doesn't

unsigned int f1(unsigned int i)
{
        return 1U << (31 - i);
}

unsigned int f2(unsigned int i)
{
        return (1U << 31) >> i;
}

test3.o:     file format elf32-powerpc


Disassembly of section .text:

00000000 <f1>:
   0:   20 63 00 1f     subfic  r3,r3,31
   4:   39 20 00 01     li      r9,1
   8:   7d 23 18 30     slw     r3,r9,r3
   c:   4e 80 00 20     blr

00000010 <f2>:
  10:   3d 20 80 00     lis     r9,-32768
  14:   7d 23 1c 30     srw     r3,r9,r3
  18:   4e 80 00 20     blr

Reply via email to