[PATCH] D65402: [Attributor][MustExec] Deduce dereferenceable and nonnull attribute using MustBeExecutedContextExplorer

Hideto Ueno via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 09:43:20 PDT 2019


uenoku created this revision.
uenoku added reviewers: jdoerfert, sstefan1.
Herald added subscribers: llvm-commits, jfb, hiraditya.
Herald added a project: LLVM.

In D65186 <https://reviews.llvm.org/D65186> and related patches, MustBeExecutedContextExplorer is introduced. This enables us to traverse instructions guaranteed to execute from function entry. If we can know the argument is used as `dereferenceable` or `nonnull` in these instructions, we can mark `dereferenceable` or `nonnull` in the argument definition:

1. Memory instruction (similar to D64258 <https://reviews.llvm.org/D64258>)

Trace memory instruction pointer operand. Currently, only inbounds GEPs are traced.

  define i64* @f(i64* %a) {
  entry:
    %add.ptr = getelementptr inbounds i64, i64* %a, i64 1
  ; (because of inbounds GEP we can know that %a is at least dereferenceable(16))
    store i64 1, i64* %add.ptr, align 8
    ret i64* %add.ptr ; dereferenceable 8 (because above instruction stores into it)
  }



2. Propagation from callsite (similar to D27855 <https://reviews.llvm.org/D27855>)

If `deref` or `nonnull` are known in call site parameter attributes we can also say that argument also that attribute.

  declare void @use3(i8* %x, i8* %y, i8* %z);
  declare void @use3nonnull(i8* nonnull %x, i8* nonnull %y, i8* nonnull %z);
  
  define void @parent1(i8* %a, i8* %b, i8* %c) {
    call void @use3nonnull(i8* %b, i8* %c, i8* %a) 
  ; Above instruction is always executed so we can say that at parent1(i8* nonnnull %a, i8* nonnull %b, i8* nonnull %c)
    call void @use3(i8* %c, i8* %a, i8* %b)
    ret void
  }

Note: The bridge between MustBeExecutedContextExploler and Attributor is now under construction. Therefore, in this patch, MustBeExecutedContextExplorer is constructed every iteration (this is perhaps very costly) for now. This should be fixed later.


https://reviews.llvm.org/D65402

Files:
  llvm/include/llvm/Analysis/ValueTracking.h
  llvm/lib/Transforms/IPO/Attributor.cpp
  llvm/test/Transforms/FunctionAttrs/arg_nocapture.ll
  llvm/test/Transforms/FunctionAttrs/arg_returned.ll
  llvm/test/Transforms/FunctionAttrs/nonnull.ll
  llvm/test/Transforms/FunctionAttrs/nosync.ll
  llvm/test/Transforms/FunctionAttrs/read_write_returned_arguments_scc.ll
  llvm/test/Transforms/InferFunctionAttrs/dereferenceable.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65402.212179.patch
Type: text/x-patch
Size: 21720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190729/86d83d98/attachment.bin>


More information about the llvm-commits mailing list