[Bug other/55181] New: [4.7/4.8 Regression] Expensive shift loop where a bit-testing instruction could be used

gjl at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Nov 2 16:06:00 GMT 2012


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

             Bug #: 55181
           Summary: [4.7/4.8 Regression] Expensive shift loop where a
                    bit-testing instruction could be used
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: gjl@gcc.gnu.org
            Target: avr


The following C code:

unsigned char lfsr (unsigned long number)
{
  unsigned char b = 0;
  if (number & (1L << 29)) b++;
  if (number & (1L << 13)) b++;

  return b;
}

compiles to a right shift 29 bits of number which is very expensive because AVR
has no barrel shifter.  Instead, a bit-testing instruction could be used which
takes just a few cycles and not more than 100 like with the right shift.

4.6.2 uses a bit testing instruction.

== Command line ==



More information about the Gcc-bugs mailing list