[LLVMdev] Prevent instruction elimination

John Criswell
Mon, 25 Oct 2010 14:33:11 -0000

On 10/25/10 4:13 AM, Xinfinity wrote:
> Hello,
>
> Does there exist something like a "dummy" instruction that is not
removed by
> the optimizers, even if it seems to be dead code?
> I want to use such instructions to carry metadata information, but they
> should have a minimal impact on the code generation and optimization. I
used
> an add instruction:

You may want to use LLVM Metadata features.  Search for MDNode in the
doxygen docs for some information on how to create metadata.

Alternatively, you can use calls to external functions.  These are
seldomly optimized since optimizations assume that external functions
can have undetermined side effects.

-- John T.

> %0 = add i8 1, 2,  !pragma_instrument_mem_add !0    ;<i8>  [#uses=0]
>
> which should not carry any dependencies, if inserted inside a loop for
> instance. But the problem is that it is removed when I use the optimization
> level -O2. Is there a way to prevent this?
> I would like to attach metadata to instructions rather than using
intrinsics
> that reference metadata.
>
>
> Thank you,
> Alexandra