On Mon, Aug 20, 2007 at 06:30:27PM +0100, Andrew Coppin wrote:
> Stefan O'Rear wrote:
>> On Sun, Aug 19, 2007 at 12:53:07PM +0100, Andrew Coppin wrote:
>>   
>>> Does GHC do stuff like converting (2*) into (shift 1) or converting x + x 
>>> into 2*x?
>>
>> For a good time, compile some code which uses even or odd :: Int -> Bool
>> using -O2 -fasm -ddump-asm...  The compiler *really* shouldn't be using 
>> 'idivl'.
>>
>> (If you use -fvia-C -optc-O2, the C compiler will notice the operations
>> and optimize it itself.  This is one of the very few areas where -fvia-C
>> is still better.)
>
> The way I heard it is that compilation via C is "always better", though 
> they "plan" to change that some day. I don't know how true that is...

Currently, it's never worse.  GHC's backend is about as good as GCC;
most of the optimiations it doesn't do are not possible for GCC because
of various lack-of-information problems (the stack pointer never aliases
the heap pointer, stuff like that).  It's conceivable that at some point
-fasm will be faster, because you have the possibility of much more
accurate aliasing information inside the compiler, than can be coded in
C.  In the meantime, note that the runtime difference is less than 3%
and the compile time difference is over 100%, so it's only worthwhile if
you expect *this version* of your program to be used more than 30 times,
ie releases only.

Stefan

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to