[LLVMdev] logic function optimization: IAR 1 - LLVM 0 ?

matic at nimp.co.uk matic at nimp.co.uk
Sat Feb 2 15:50:31 PST 2013


 

I gave the following function to IAR compiler (targeting CortexM0)
and to clang/LLVM 3.2 (clang -O3 -target thumbv6-eabi -emit-llvm) 

int
calleeSave8(int in[]){
 int out=0;
 int i;
 for(i=0;i<8;i++){
 out ^=
in[i] & in[(i+1)%8];
 }//expand to out =
(in[0]&in[1])^(in[1]&in[2])^(in[2]&in[3])^(in[3]&in[4])^(in[4]&in[5])^(in[5]&in[6])^(in[6]&in[7])^(in[7]&in[0])

 return out;
} 

In such case, IAR compiler is able to factor out half
of the and operations so it performs 4 and + 7 xor, LLVM factored only
one and operation so it performs 7 and + 7 xor. (I looked at IR code and
assembly output) 

Did I miss some option that would improve the result
? 

My understanding is that this kind of optimization should be done by
the target independent part of the code generator, backends should not
have to implement such optimization right ? 

Cheers, 

Sebastien 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130202/50eed9cc/attachment.html>


More information about the llvm-dev mailing list