[LLVMdev] Memory optimizations for LLVM JIT
Richard Osborne
richard at xmos.com
Tue Aug 20 12:24:09 PDT 2013
On 20 Aug 2013, at 08:23, 王振江 <cryst216 at gmail.com<mailto:cryst216 at gmail.com>> wrote:
A GlobalValue was declared and mapped to the variable p.
Some LLVM IR instructions were created according to those generated by LLVM from source.
I.e., load p, load a[1] based on p, load p again, store a[2] based on p, etc.
The machine code turned out to be slightly optmized, as shown on the left.
I suspect this is due to possible aliasing. If p somehow pointed to itself then the store p->a[x] might change the value of of p so p must be reloaded each time. Clang will emit TBAA metadata nodes (http://llvm.org/docs/LangRef.html#tbaa-metadata) that let the optimizers know the load of p can't alias the stores through p since they are have different high-level types. Without the TBAA metadata the optimizers must be conservative.
Things were getting better after the GlobalVariable of p was set as a constant.
Redundant Loads of p (line 5, 8 and 11) were removed, and so was line 12 because of line 10.
This makes sense - if p is constant no store can possibly change the value of p so it doesn't need to be reloaded.
However, I could not make it better any more, although optimal machine code just need those marked with '*'.
This is strange, I'm not what sure what is going on here - assuming you are running the same passes I'd expect no difference here.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130820/9d57fe45/attachment.html>
More information about the llvm-dev
mailing list