<div dir="ltr"><div><div>You have not installed the DataLayout in the Module, as I had pointed out earlier.<br><br></div>Compile a small program using clang, to get IR. You will notice a "target datalayout" declaration at the top of the IR. There is no such declaration in your IR.<br><br></div>This is precisely the problem I had. You need to add the DataLayout to the Module, at which point a "target datalayout" declaration will appear in your IR, and the optimization passes will have enough alias information to be able to eliminate your redundant loads.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 23, 2015 at 2:02 AM, Dibyendu Majumdar <span dir="ltr"><<a href="mailto:mobile@majumdar.org.uk" target="_blank">mobile@majumdar.org.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 23 February 2015 at 01:29, Kamal Sharma <<a href="mailto:kgs1.rice@gmail.com">kgs1.rice@gmail.com</a>> wrote:<br>
> Hi  Dibyendu,<br>
><br>
> It would be very helpful if you could post the original source code or<br>
> snippet.<br>
> That way, one can investigate deeper to understand the problem.<br>
><br>
> Regards,<br>
> Kamal Sharma<br>
><br>
<br>
</span>Hi Kamal,<br>
<br>
Sure. I guess I ought to create a test that one can look in isolation.<br>
<br>
I am working on building a JIT compiler for Lua (actually a derivative<br>
of Lua). It is currently work in progress.<br>
The approach is to compile Lua bytecodes into LLVM IR.<br>
<br>
The IR generated from my code is here (after optimization I should add):<br>
<a href="https://github.com/dibyendumajumdar/ravi/blob/master/clang-output/lua_op_loadk_return_ravi.ll" target="_blank">https://github.com/dibyendumajumdar/ravi/blob/master/clang-output/lua_op_loadk_return_ravi.ll</a><br>
<br>
I am using the output from Clang as a guide to generating IR. So I<br>
write small snippets of code in C which are equivalent to Lua<br>
bytecodes - then use Clang to emit the IR. I use this to work out the<br>
IR I need to build.<br>
<br>
The C equivalent of the program I am compiling is here:<br>
<a href="https://github.com/dibyendumajumdar/ravi/blob/master/clang-output/lua_op_loadk_return.c" target="_blank">https://github.com/dibyendumajumdar/ravi/blob/master/clang-output/lua_op_loadk_return.c</a><br>
<br>
The difference between the C version and what I generate is that I put<br>
a load of the "base" pointer at the beginning of every Lua opcode.<br>
This is because some Lua opcodes can reallocate the memory pointed to<br>
by base. I was hoping that the optimizer will get rid of the redundant<br>
stuff.<br>
<br>
The code generation is all done here:<br>
<br>
<a href="https://github.com/dibyendumajumdar/ravi/blob/master/src/ravijit.cpp" target="_blank">https://github.com/dibyendumajumdar/ravi/blob/master/src/ravijit.cpp</a><br>
<br>
I don't expect you to wade through all this - but I will be grateful<br>
for any help / guidance you can provide.<br>
<br>
Thanks and Regards<br>
<div class="HOEnZb"><div class="h5">Dibyendu<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div>