
Hi David,
------------------- Question: can't it use cheap multiplication and shift instead of expensive division here? I know that such optimisation is implemented at least to some extent for C--. I suppose it also won't do anything smart for expressions like a*4 or a/4 for the same reason. There isn't really any optimisation done on Cmm and the native code generator doesn't do much optimisation itself, hence you get the more direct forward translation. This kind of code is where the LLVM backend does well in comparison. I haven't tried benchmarking the performance of -fasm vs -fllvm for this code but if you eyeball the assembly code produced by -fllvm then you'll see it uses shifts and other magic.
Cheers, David
Well.. I found some places in C-- compiler which are supposed to convert division and multiplication by 2^n into shifts. And I believe these work sometimes. However in this case I am a bit puzzled because even if I change the constants in my example to 2^n like 1024 the code is not optimised. By the way, is there any kind of documentation on how to hack C-- compiler? In particular, I am interested in: * how to run its optimiser against some C-- code and see what does it do * knowing more about its internals With kind regards, Denys Rtveliashvili