[LLVMdev] Compiler opt is turned off ?
Somenath Chakraborty
some.chak at gmail.com
Fri Jan 4 04:49:47 PST 2013
Hello,
I was trying to run few testcases and see how llvm optmizes different
scenarios. I have a small testcase like:
#include <stdio.h>
int a, b, c;
int
main()
{
a = b + c;
c = a;
if (a == b)
b = c;
else
b = a;
printf( " a = %d \n ", a );
return 0;
}
The corresponding llvm IR is ( clang test.c -S -emit-llvm -o - -O3 ) :
define i32 @main() nounwind uwtable {
entry:
%0 = load i32* @b, align 4, !tbaa !4
%1 = load i32* @c, align 4, !tbaa !4
%add = add nsw i32 %1, %0
store i32 %add, i32* @a, align 4, !tbaa !4
store i32 %add, i32* @c, align 4, !tbaa !4
store i32 %add, i32* @b, align 4, !tbaa !4
%call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([11
x i8]* @.str, i64 0, i64 0), i32 %add) nounwind
ret i32 0
}
Here, I can see, although the *copy-propagation* is kicked in, but, *constant
propagation* is not happening. I assume the reason behind this is that a, b
and c are all global variables. Also, as no one is reading b and c
after the statement "a = b + c", should they not get optimized out ( from
"c = a" to end of function)?
Now, if a, b and c are made locals, all the optmizations are kicked in:
define i32 @main() nounwind uwtable {
entry:
%call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([11
x i8]* @.str, i64 0, i64 0), i32 0) nounwind
ret i32 0
}
Are we little conservative on global variables even though *they don't have
readers* and debug mode is *OFF* ? Or, is it supported under some FLAG? Am
I missing something .... ?
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130104/3f056180/attachment.html>
More information about the llvm-dev
mailing list