[PATCH] Add a dereferencable attribute

hfinkel at anl.gov hfinkel at anl.gov
Wed Jul 9 20:19:56 PDT 2014


Hi chandlerc, aschwaighofer, nlewycky, reames, luqmana,

This patch adds a dereferencable attribute. In some sense, this is a companion to the nonnull attribute, but specifies that the pointer is known to be dereferencable in the same sense as a pointer generated by alloca is known to be dereferencable.

My primary use case for this is C++ references that are passes as function parameters and used in loops. For example,

void foo(int * __restrict__ a, int * __restrict__ b, int &c, int n) {
  for (int i = 0; i < n; ++i)
    if (a[i] > 0)
      a[i] = c*b[i];
}

Currently, we generate a load of 'c' in every loop iteration because we can't prove that there is no control dependence on the dereferencability of 'c' from the if condition. But because 'c' is a reference, we know it must point to something, and since nothing else in the loop can alias it, it is safe to load it in the preheader.

(there is a simple companion Clang patch, which I'll also post.)

http://reviews.llvm.org/D4449

Files:
  docs/LangRef.rst
  include/llvm-c/Core.h
  include/llvm/Bitcode/LLVMBitCodes.h
  include/llvm/IR/Argument.h
  include/llvm/IR/Attributes.h
  lib/AsmParser/LLLexer.cpp
  lib/AsmParser/LLParser.cpp
  lib/AsmParser/LLToken.h
  lib/Bitcode/Reader/BitcodeReader.cpp
  lib/Bitcode/Writer/BitcodeWriter.cpp
  lib/IR/Attributes.cpp
  lib/IR/Function.cpp
  lib/IR/Value.cpp
  test/Bitcode/attributes.ll
  test/Transforms/LICM/hoist-deref-load.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4449.11238.patch
Type: text/x-patch
Size: 12344 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140710/64f1b07e/attachment.bin>


More information about the llvm-commits mailing list