<div dir="ltr">If you mark that store as `volatile`, then LLVM should be unable to remove it or the alloca (while still being free to do load-store forwarding, if it deems that profitable), which should usually also keep the debug info intact as a side-benefit.</div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jul 11, 2016 at 4:45 PM David Jones via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div>I have code along the lines of:<br><br></div>void foo(struct A *a) {<br></div>    struct B *b = a->m_B;<br></div>    /* do a whole bunch of things with b */<br>}<br><br></div>When LLVM generates code for this, it sees that after initializing b, a is no longer used, so it is optimized out.<br><br></div>Unfortunately, for debug, I'd like the value for a to be kept around, if only so that I can determine the value of b and go from there.  I don't care if a is spilled to the stack and never referenced thereafter, as long as it is available for debug.<br><br></div>Is there any way of marking a Value* as "precious", not to be optimized out?<br><br></div>Simply storing a to a local variable (result of alloca in the first basic block) and calling llvm.dbg.declare does not appear to be sufficient:<br><br></div>define void @foo(%A*) {<br></div>    %2 = alloca %A*<br></div>    store %0, %2<br></div>    call void @llvm.dbg.declare(metadata %A* %2, metadata !101, metadata !100), !dbg ...<br><br><div><div><div><div>!100 = !DIExpression()<br></div><div>!101 = !DILocalVariable(...)<br><br></div><div><br></div></div></div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>