[LLVMdev] clang optimizer does not remove unused/uneeded variables(and accesses) from global scope
Dennis Luehring
dl.soluz at gmx.net
Thu Jul 5 02:23:49 PDT 2012
hi llvmdev list
im currently investigating a missing optimizer feature in VS2010 - and
comparing the VS2010 results with the result of clang 3.1
i've downloaded clang from http://llvm.org/releases/download.html ->
Experimental Clang Binaries for Mingw32/x86
clang --version
clang version 3.1 (branches/release_31)
Target: i686-pc-mingw32
Thread model: posix
----- test.c
typedef unsigned char byte_t;
typedef unsigned int dword_t;
byte_t byte;
dword_t dword;
int main(int argc, char** argv)
{
dword_t random = (dword_t)argv;
byte = (byte_t)random;
dword = (dword_t)random;
dword_t result = 3*(byte+dword);
return result;
}
-------
compiled with "clang -O3 test.c"
produces this code for the main
.text:004012E0 sub_4012E0 proc near ; CODE XREF:
sub_401020+91
.text:004012E0
.text:004012E0 arg_4 = dword ptr 0Ch
.text:004012E0
.text:004012E0 push ebp
.text:004012E1 mov ebp, esp
.text:004012E3 call sub_4014C0
.text:004012E8 mov eax, [ebp+arg_4] ; dword_t random
= (dword_t)argv;
.text:004012EB mov byte_402000, al
.text:004012F0 mov dword_402004, eax
.text:004012F5 movzx ecx, al
.text:004012F8 add ecx, eax
.text:004012FA lea eax, [ecx+ecx*2]
.text:004012FD pop ebp
.text:004012FE retn
.text:004012FE sub_4012E0 endp
but why are these two lines not removed by the optimizer?
.text:004012EB mov byte_402000, al
.text:004012F0 mov dword_402004, eax
no access before, no access after - even the main-code itself isn't
using the variables for reading
VS2010 behaves the same - but clang is still much better in other cases :)
More information about the llvm-dev
mailing list