[LLVMdev] Prevent instruction elimination

John Criswell criswell at illinois.edu
Mon Oct 25 08:52:03 PDT 2010


On 10/25/10 10:43 AM, Duncan Sands wrote:
> Hi John,
>
>> As for instructions, I don't know of an instruction which does nothing,
>> won't be removed by optimization, and yet does not inhibit
>> optimization.  Perhaps a local alloca and a volatile load or store would
>> do the trick?  Being volatile, the compiler won't remove it (or if it
>> does, it's a bug, and you should file a bug report), and since it loads
>> from a memory object not used for anything else, alias analysis should
>> be able to see that it doesn't interefere with any other load/store.
> LLVM certainly will remove volatile loads and stores to local variables
> (at least in simple situations).  I suggest using an empty asm statement.

Really?  Isn't that illegal?  The whole point of "volatile" is to tell 
the compiler that it should not remove a load/store.  Optimizing them 
away seems counter-intuitive and directly contradicts the documented 
behavior in the LLVM Language Reference manual (which states that the 
number of volatile loads/stores will not be changed).

-- John T.

> Ciao,
>
> Duncan.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list