<div dir="ltr">
Hello everyone,<br><br>We propose the addition of a GlobalMemOnly attribute to LLVM.<br><br>Definition:<br><br>This
attribute indicates that the only memory accessed inside a function,
that is visible to the callee, is global memory. If the function reads
or writes other memory that is visible to the callee, the behavior is
undefined.<br><br>Motivation:<br><br>Memory attributes already exist for
specifying the memory locations accessed by a function, such as
ArgMemOnly and InacessibleMemOnly. Similarly, there are attributes for
describing memory behaviour, such as ReadOnly and WriteOnly.<br><br>However,
no attributes exist for differentiating the types of memory objects
that functions can access, such as global objects and objects created by
alloca. We would like to start by introducing an attribute to deal with
functions that only access global objects.<br><br>The addition of the GlobalMemOnly attribute can benefit LLVM as follows:<br><br>1.
Improves Alias Analysis, since this information can be used to improve
the determination of aliasing between functions and memory locations
that point to global objects.<br><div><br></div><div>2. Provides
Transforms with greater information: many math lib calls only modify the
global variable errno. Unnecessary loads of the call arguments can
therefore be removed, since the calls will have no side-effects on them.</div><br>Patches Overview:<br><br>1. Definition of GlobalMemOnly in the AsmParser, IR, and LLVM Bitcode. It is also defined in the LangRef.<br><br><a href="https://reviews.llvm.org/D109644" target="_blank">https://reviews.llvm.org/D109644</a><br><br>2.
Support is added to Alias Analysis. If a function is GlobalMemOnly and a
memory location does not point to a global object, getModRefInfo can
infer that no aliasing between the function and the location can occur.
This patch also adds a regression test for BasicAA.<br><br><a href="https://reviews.llvm.org/D109647" target="_blank">https://reviews.llvm.org/D109647</a><br><br>3.
Certain math lib calls are assigned GlobalMemOnly, since they only
modify the global variable errno. These calls include common functions,
such as atan, exp, and log.<br><br><a href="https://reviews.llvm.org/D109648" target="_blank">https://reviews.llvm.org/D109648</a><br><br>Please
let us know of any thoughts you may have regarding this attribute’s
implementation and use cases. We believe that it can strengthen LLVM’s
alias analysis and optimization passes if added.<br><br>Thanks,<br>Mugilan</div>