[LLVMdev] question on constant folding
Seung Jae Lee
lee225 at illinois.edu
Tue Jun 10 22:05:12 PDT 2008
Hello, LLVMers.
I have a quick question for constant folding.
When I treated a code twice by changing the data type from 'floating point' to 'integer,'
What I found was:
optimization is done better for the code having int's.
E.g., for this simple code:
-------------------------------------------------------------
double foo() {
double i,j;
double sum = 0;
for (i=0; i<100; i++) {
sum += i;
for (j=0; j<100; j++)
sum += 2;
}
return sum;
}
-------------------------------------------------------------
$llvm-gcc -O4 -emit-llvm foo.c -c -o foo.bc
$opt -std-compile-opts -reg2mem foo.bc -o foo_optimized.bc
gave me a really long LLVM IR code with many basic blocks..
However, when I just changed the types to 'long' as follows:
-------------------------------------------------------------
long foo() {
long i,j;
long sum = 0;
for (i=0; i<100; i++)
{
sum += i;
for (j=0; j<100; j++)
sum += 2;
}
return sum;
}
-------------------------------------------------------------
This code simply gave me:
-------------------------------------------------------------
define i32 @foo() nounwind {
%"reg2mem alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
ret i32 24950
}
-------------------------------------------------------------
Could you anybody tell me why interger type code shows the better performance in constant folding with LLVM?
Thank you in advance..
SJ
More information about the llvm-dev
mailing list