[llvm] 6cd6733 - [LangRef][AliasAnalysis] Clarify `noalias` affects only modified objects

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 18:42:05 PDT 2020


Author: Johannes Doerfert
Date: 2020-04-01T20:40:55-05:00
New Revision: 6cd673345cfa7b1dc25568ac9fd45e23402bbd02

URL: https://github.com/llvm/llvm-project/commit/6cd673345cfa7b1dc25568ac9fd45e23402bbd02
DIFF: https://github.com/llvm/llvm-project/commit/6cd673345cfa7b1dc25568ac9fd45e23402bbd02.diff

LOG: [LangRef][AliasAnalysis] Clarify `noalias` affects only modified objects

We already mention that `noalias` is modeled after the C99 `restrict`
qualifier but we did omit one important requirement in the description.
For the restrict guarantees the object affected has to be modified
during the execution of the function, in any way (see 6.7.3.1.4 in [0]).

There are two reasons we want this restriction as well:
  1) To match the `restrict` semantics when we lower it to `noalias`.
  2) To allow the reasoning that the object pointed to by a `noalias`
     pointer is not modified through means not derived from this
     pointer. Hence, following the uses of that pointer is sufficient
     to determine potential modifications.

The discussion on this came up as part of D73428. In that patch the
Attributor is taught to derive `noalias` for call site arguments based
on alias queries against objects that are accessed in the callee. This
is possible even if the pointer passed at the call site was "not-`noalias`".
To simplify the logic there *and* to allow the use of `noalias` as
described in 2) above, it is beneficial to follow the C `restrict`
semantics in cases where there might be "read-read-aliases". Note that
 AliasAnalysis* queries for read only objects already result in
 `NoAlias` even if the pointers might "alias".

 * From this point of view our Alias Analysis is basically a Dependence
   Analysis.

[0] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D74935

Added: 
    

Modified: 
    llvm/docs/LangRef.rst

Removed: 
    


################################################################################
diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 058e76fc2b0c..f6c0a66f4407 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -1107,14 +1107,16 @@ Currently, only the following parameter attributes are defined:
 .. _noalias:
 
 ``noalias``
-    This indicates that objects accessed via pointer values
+    This indicates that memory locations accessed via pointer values
     :ref:`based <pointeraliasing>` on the argument or return value are not also
     accessed, during the execution of the function, via pointer values not
-    *based* on the argument or return value. The attribute on a return value
-    also has additional semantics described below. The caller shares the
-    responsibility with the callee for ensuring that these requirements are met.
-    For further details, please see the discussion of the NoAlias response in
-    :ref:`alias analysis <Must, May, or No>`.
+    *based* on the argument or return value. This guarantee only holds for
+    memory locations that are *modified*, by any means, during the execution of
+    the function. The attribute on a return value also has additional semantics
+    described below. The caller shares the responsibility with the callee for
+    ensuring that these requirements are met.  For further details, please see
+    the discussion of the NoAlias response in :ref:`alias analysis <Must, May,
+    or No>`.
 
     Note that this definition of ``noalias`` is intentionally similar
     to the definition of ``restrict`` in C99 for function arguments.


        


More information about the llvm-commits mailing list