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.
On Tue, 13 Feb 2007, Nicola Lugato wrote:> Hi, i have some code that allocate some memory, store the pointer to a > variable, read it back and deallocates it, like this:ok> 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?This looks like a simple missed optimization.> and where did that getelementptr came from?This is just passing a pointer to the first byte of the array into the free instruction. This has the same semantics as freeing the pointer to the array, since they are the same value.> I have the feeling that i'm missing something.Nope, I don't think so. Please feel free to file an enhancement request for us to catch this case! -Chris -- http://nondot.org/sabre/ http://llvm.org/
I've made some other test and it looks like it don't remove even simple malloc/free couple. Maybe there's something wrong in the way i use the opt command. How can i tell him to optimize at best, whitout specifing each pass? I'm not using c/c++ frontend, just the assembler. Thanks in advance On 2/14/07, Chris Lattner <sabre at nondot.org> wrote:> On Tue, 13 Feb 2007, Nicola Lugato wrote: > > Hi, i have some code that allocate some memory, store the pointer to a > > variable, read it back and deallocates it, like this: > > ok > > > 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? > > This looks like a simple missed optimization. > > > and where did that getelementptr came from? > > This is just passing a pointer to the first byte of the array into the > free instruction. This has the same semantics as freeing the pointer to > the array, since they are the same value. > > > I have the feeling that i'm missing something. > > Nope, I don't think so. Please feel free to file an enhancement request > for us to catch this case! > > -Chris > > -- > http://nondot.org/sabre/ > http://llvm.org/ > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Possibly Parallel Threads
- [LLVMdev] Unused malloc/free don't get optimized
- [LLVMdev] Unused malloc/free don't get optimized
- [LLVMdev] Unused malloc/free don't get optimized
- [LLVMdev] FW: question about malloc call vs. instruction
- [LLVMdev] Stupid '-load-vn -licm' question (LLVM 1.6)