[LLVMdev] Unused malloc/free don't get optimized

Nicola Lugato nicola.lugato at gmail.com
Tue Feb 13 10:02:52 PST 2007


Hi, i have some code that allocate some memory, store the pointer to a
variable, read it back and deallocates it, like this:

int %main(int %argc, ubyte** %argv)
{
%c_19 = alloca ubyte*
%malloc_206  = malloc ubyte, uint 10
store ubyte* %malloc_206, ubyte** %c_19
%tmp_207 = load ubyte** %c_19
free ubyte* %tmp_207

ret int 0
}

i expected the optimized to remove everything, but after running it
the code i get is:

int %main(int %argc, ubyte** %argv) {
	%malloc_206 = malloc [10 x ubyte]
	%malloc_206.sub = getelementptr [10 x ubyte]* %malloc_206, int 0, int 0
	free ubyte* %malloc_206.sub
	ret int 0
}

Why didn't he optimized it out? and where did that getelementptr came from?
I have the feeling that i'm missing something.



More information about the llvm-dev mailing list