<div dir="ltr"><div><div>Not sure if this is your problem, but it was mine:<br><br></div>You must create (or obtain) a DataLayout *and install it into the Module*.<br><br></div>It is possible to generate machine code for IR and not install the DataLayout into the Module. Rather, the DataLayout is used locally at the point where code is generated. However, if you do this, then the alias analyses required to get rid of your redundant loads and stores cannot reason about possible aliasing.<br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 22, 2015 at 3:42 PM, 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">Hi,<br>
<br>
I am generating following code:<br>
<br>
  %base = getelementptr inbounds %ravi.CallInfo* %6, i32 0, i32 4, i32 0<br>
  %7 = load %ravi.TValue** %base<br>
  %8 = bitcast %ravi.TValue* %7 to i8*<br>
  %9 = bitcast %ravi.TValue* %5 to i8*<br>
  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %8, i8* %9, i32 16, i32 8, i1 false)<br>
  %10 = load %ravi.CallInfo** %L_ci<br>
  %base1 = getelementptr inbounds %ravi.CallInfo* %10, i32 0, i32 4, i32 0<br>
  %11 = load %ravi.TValue** %base1<br>
  %12 = getelementptr inbounds %ravi.TValue* %11, i32 1<br>
  %13 = getelementptr inbounds %ravi.TValue* %5, i32 1<br>
  %14 = bitcast %ravi.TValue* %12 to i8*<br>
  %15 = bitcast %ravi.TValue* %13 to i8*<br>
  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %14, i8* %15, i32 16, i32 8, i1 false<br>
)<br>
  %16 = load %ravi.CallInfo** %L_ci<br>
  %base2 = getelementptr inbounds %ravi.CallInfo* %16, i32 0, i32 4, i32 0<br>
  %17 = load %ravi.TValue** %base2<br>
<br>
Now base, base2 and base1 are really the same - i.e., nothing's<br>
happened to change the pointer held at this location. So should I<br>
expect the redundant getelementptr and load instructions to be<br>
eliminated during optimization phase?<br>
<br>
I am using the optimisation passes as described in Kaleidoscope<br>
tutorial but it seems that the redundant loads are not being removed.<br>
<br>
Is it the call to memcpy that's preventing this?<br>
<br>
Thanks and Regards<br>
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>
</blockquote></div><br></div>