This is the mail archive of the gcc@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]

Optimizations on long long multiply/divide on PowerPC32 don't work


In yet another problem compiling the Linux kernel on PowerPC (32-bit) 
with the CVS tree, I'm running into a problem compiling something; the 
Linux kernel is expecting division of a long long by a constant value to 
be optimized and not call __divdi3, but the GCC compiler is not doing 
this.  The following program:

  long long t1(long long v)
  {
      return v / 512;
  }

will call __divdi3, even though the operation could be done much faster 
with shifts (and other stuff for handling negatives).  It turns out that 
the code to call __divdi3 is being emitted on the conversion to rtl, and 
the optimizations do not see this function call and handle it as a 
division, they just see it as a function call.  So no optimizations at 
all will be done on 64-bit multiplies and divides.  I consider this to 
be sub-optimal :-).

I can see four options to solve this problem:

  1) Add __divdi3 to the linux kernel.  I don't really think this is a 
good idea, and it shouldn't be required.
  2) Move the conversion of the division to the function call to the 
very last stages of the compiler.  IMHO, this is probably the best 
option, but it's a big job to implement, I think.
  3) Make the optimizations understand the function calls.  I don't even 
want to think about this one.
  4) Modify the tree conversions to do the optimizations there.  I have 
a patch that does this (and passes all regressions), because it was 
easy, but I consider it less optimal than option 2.

Any opinions on this?  I'll post my patch if the maintainers think 
option 4 is reasonable.

Thanks,

-Corey


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