[Bug target/47920] New: strange code generated for expression (a+7)/8

carrot at google dot com gcc-bugzilla@gcc.gnu.org
Mon Feb 28 09:31:00 GMT 2011


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

           Summary: strange code generated for expression (a+7)/8
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: carrot@google.com
            Target: arm-linux-androideabi


Compile the following code with options -mthumb -march=armv7-a -O2

int t08(int a)
{
  return (a+7)/8;
}

GCC 4.6 generates

t08:
    add    r3, r0, #14
    adds    r0, r0, #7
    it    mi
    movmi    r0, r3
    asrs    r0, r0, #3
    bx    lr


Why not simply generate

    adds    r0, r0, #7
    asrs    r0, r0, #3
    bx    lr



More information about the Gcc-bugs mailing list