[LLVMdev] Warning about variable optimized away?

Philip Reames listmail at philipreames.com
Tue Aug 5 20:31:08 PDT 2014


Dmitry,

In general, you can not safely make assumptions about your optimizer 
preserving values.  This is fundementally unsafe and is ill-advised.

For your particular example, you have a derived pointer which is live 
and a base pointer which is not.  Have you confirmed that the derived 
value (&(obj->some_member)) is available?  I would expect it to be.  
Given that, your GC has (most of) the information it needs.  
Conservative GCs typically consider interior pointers to objects (i.e. 
something which is likely a derived pointer) to be a pointer to the 
object for exactly this reason.  Now, you can run into cases where the 
compiler creates a temporary pointer outside of the object (or worse, 
into another), but these are rare in practice.  Can I ask what GC 
library you're using?  To my knowledge, most of the major ones handle 
interior pointers just fine.

If you're interested in pursuing a non-conservative root scanning 
policy, I'd suggest you look at the statepoint intrinsics implemented 
here: https://github.com/AzulSystems/llvm-late-safepoint-placement

Yours,
Philip

On 08/05/2014 11:14 AM, Reid Kleckner wrote:
> This isn't really feasible.
>
> First, you are asking for a warning from LLVM's optimizers, which we 
> strive to avoid, as they are unstable and affected by optimization levels.
>
> Second, there are many, many optimizations that transform code in ways 
> that could remove gc roots, and it is not practical to annotate them all.
>
> If you have a relocating GC, you need to implement something more 
> sophisticated like Phillip's late safepoint insertion approach.
>
> On Tue, Aug 5, 2014 at 4:55 AM, Dmitry Antipov <antipov at dev.rtsoft.ru 
> <mailto:antipov at dev.rtsoft.ru>> wrote:
>
>     Hello,
>
>     it it possible to get a kind of diagnostics if the variable
>     is totally optimized away?  For example, in:
>
>     void foo (struct some_type *obj) {
>       ... some code where 'obj' is not used ...
>       bar (obj->some_member);
>       ... some code where 'obj' is not used again ...
>       baz (obj->some_member);
>     }
>
>     'obj' is likely to be optimized away so only 'obj->some_member' really
>     exists (in a register or stack location).  Getting diagnostics
>     or preserving 'obj' may be important if there is a GC which scans
>     C stack and registers conservatively - if there is no direct reference
>     to 'obj', it's likely to be reclaimed and so 'obj->some_member'
>     becomes garbage.
>
>     Dmitry
>     _______________________________________________
>     LLVM Developers mailing list
>     LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu>
>     http://llvm.cs.uiuc.edu
>     http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140805/52ab46c5/attachment.html>


More information about the llvm-dev mailing list