<div dir="ltr"><div><div><div><div><div><div>Hello LLVM devs,<br><br></div>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.<br><br></div>Here is one possible example:<br><br>void f(int x, int z)<br></div>{<br></div>   const int y = x+g(z);<br></div>   //...<br></div><div><div><div>}<br><br></div><div>One of the ways to compile above code is to:<br><br></div><div>%y = alloca i32<br></div><div>; ... perform y computation here and store result into %y_tmp<br></div><div>store i32 %y_tmp, i32* %y<br></div><div>; ... continue execution<br></div><div><br></div><div>From now on we have two choices on what to do with it. <br><br>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. <br></div><div>2. I can mark store and subsequent loads using constant tbaa metadata.<br><br></div><div>Now here are few questions I have:<br></div><div>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?<br></div><div>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.<br></div><div>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. <br><br></div><div>Cheers, Przemek<br></div><div><br></div></div></div></div>