This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/23669] New: fold does convert (-a)/10 into a/-10.


Another idea from LLVM.
The following two functions should be the same asm:
int f(int a)
{
  return (-a)/10;
}
int f1(int a)
{
  return a/-10;
}

----
We currently get on PPC:
_f:
        lis r0,0x6666
        neg r3,r3
        ori r0,r0,26215
        mulhw r0,r3,r0
        srawi r3,r3,31
        srawi r0,r0,2
        subf r3,r3,r0
        blr
_f1:
        lis r0,0x6666
        ori r0,r0,26215
        mulhw r0,r3,r0
        srawi r3,r3,31
        srawi r0,r0,2
        subf r3,r0,r3
        blr

As you can see f1 has one less instruction which should be better.

-- 
           Summary: fold does convert (-a)/10 into a/-10.
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P2
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pinskia at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
OtherBugsDependingO 19987
             nThis:


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]