[llvm-dev] Marking memory as immutable in LLVM IR

Przemek LeĊ›niak via llvm-dev llvm-dev at lists.llvm.org
Fri Jul 14 10:15:23 PDT 2017


Hello LLVM devs,

I am working on LLVM backend for Chapel compiler. I'd like to use
'llvm.invariant.start' and constant type-based alias analysis metadata
(tbaa). I have read documentation and looked how clang uses
'llvm.invariant.start' in code generation and it's still not clear to me
how to use both of these correctly. The problem I have is when should I use
any of them and how are they really different.

Here is one possible example:

void f(int x, int z)
{
   const int y = x+g(z);
   //...
}

One of the ways to compile above code is to:

%y = alloca i32
; ... perform y computation here and store result into %y_tmp
store i32 %y_tmp, i32* %y
; ... continue execution

>From now on we have two choices on what to do with it.

1. I can either use `llvm.invariant.start` on %y to mark that %y is never
going to change. In this case, I'm unsure whether I should unmark %y with
'llvm.invariant.end' after I'm done executing.
2. I can mark store and subsequent loads using constant tbaa metadata.

Now here are few questions I have:
1. Should I go with 1, or with 2 in this case? If I have to go with 1,
should I unmark memory with llvm.invariant.end after function is done
executing?
2. In general, when should I use tbaa const and llvm.invariant? I can think
of: global constants, local loop constants, local if constants, constant
arguments in function.
3. Which optimizations does llvm.invariant.start and tbaa impact? How can I
possibly check that I've added this metadata correctly and it indeed helps?
Possibly by seeing that some optimization occured with new information.

Cheers, Przemek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170714/6593ed96/attachment.html>


More information about the llvm-dev mailing list