Index: docs/LangRef.rst =================================================================== --- docs/LangRef.rst +++ docs/LangRef.rst @@ -12275,6 +12275,64 @@ that the optimizer can otherwise deduce or facts that are of little use to the optimizer. +.. _int_noalias: + +'``llvm.noalias``' Intrinsic +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Syntax: +""""""" + +:: + + declare * @llvm.noalias.p
(* %ptr, metadata %scopes) + +Overview: +""""""""" + +``llvm.noalias`` allows the optimizer to assume that memory accesses using +pointers :ref:`based ` on the return value don't alias with +memory accesses, tagged with the provided ``noalias`` scope, using pointers not +derived from the return value. + +Arguments: +"""""""""" + +The first argument is the pointer on which the aliasing assumption is being +placed. This pointer value is returned, but parts of the optimizer ignore this +fact so that data dependencies on the return value will be maintained. The +aliasing assumptions apply only to uses of pointers +:ref:`based ` on the return value. + +The second argument is metadata that is a list of ``noalias`` metadata +references. The format is identical to that required for ``noalias`` metadata. +This list should have only one element. + +Semantics: +"""""""""" + +``llvm.noalias`` allows the optimizer to assume that memory accesses using +pointers :ref:`based ` on from the return value don't alias +with memory accesses, tagged with compatible ``noalias`` scopes (i.e. the scope +provided to the intrinsic must be one of the scopes with which the access is +tagged), using pointers not based on the return value. See the description of +``alias.scope`` and ``noalias`` metadata for more information. The aliasing +assumptions apply only to uses of pointers based on the return value, and +accesses using those pointers must themselves be tagged with ``noalias`` +metadata with compatible scopes. + +Unlike ``alias.scope`` metadata, which applies to only the access to which it +is attached, the ``llvm.noalias`` intrinsic applies to all pointers based on +from the return value. Placing an ``llvm.noalias`` intrinsic outside of a loop +provides a mechanism for communicating that certain memory accesses don't alias +with uses of a pointer in any loop iteration. This works only if the +``llvm.noalias`` intrinsic itself dominates the loop body. + +Note that the use of ``alias.scope`` metadata does not block potential +optimizations, as ``llvm.noalias`` might, and so use of ``alias.scope`` +metadata when possible is recommended. Nevertheless, no code is generated for +this intrinsic. + .. _type.test: '``llvm.type.test``' Intrinsic Index: include/llvm/IR/Intrinsics.td =================================================================== --- include/llvm/IR/Intrinsics.td +++ include/llvm/IR/Intrinsics.td @@ -329,6 +329,13 @@ // control dependencies will be maintained. def int_assume : Intrinsic<[], [llvm_i1_ty], []>; +// This intrinsic does not actually write to memory, but it is marked that way +// to maintain proper control dependencies. The metadata argument refers to a +// list of alias.scope metadata entries. +def int_noalias : Intrinsic<[llvm_anyptr_ty], + [LLVMMatchType<0>, llvm_metadata_ty], + [IntrArgMemOnly]>; + // Stack Protector Intrinsic - The stackprotector intrinsic writes the stack // guard to the correct place on the stack frame. def int_stackprotector : Intrinsic<[], [llvm_ptr_ty, llvm_ptrptr_ty], []>;