This is an archive of the discontinued LLVM Phabricator instance.

`nonnull` argument attribute.
AbandonedPublic

Authored by luqmana on Apr 15 2014, 9:02 PM.

Details

Reviewers
nicholas
Summary

This patch adds a new argument attribute nonnull. This lets LLVM get rid of certain null checks. GCC already has a nonnull attribute. Also, this would be useful in Rust since we can mark a lot of our pointers as such.

Diff Detail

Event Timeline

luqmana updated this revision to Unknown Object (????).Apr 15 2014, 9:05 PM

Added test.

Thanks for working on this!

When uploading a patch to phabricator, please increase the number of context lines as documented here: http://llvm.org/docs/Phabricator.html

test/Analysis/BasicAA/nonnull.ll
1 ↗(On Diff #8553)

This test is in the wrong place. You seem to be testing instcombine here, not basicaa, and so the test should be in test/Transforms/InstCombine somewhere.

luqmana updated this revision to Unknown Object (????).Apr 16 2014, 7:14 AM

Added more context and moved test.

luqmana updated this revision to Unknown Object (????).Apr 16 2014, 10:22 AM

I didn't see any obvious problems remaining. LGTM.

rnk added a comment.Apr 16 2014, 6:06 PM

Seems pretty cool.

Is it meaningful to have a nonnull attribute on a non-pointer type? Mind outlawing that in the Verifier, and then adding a verifier test?

Your change to lib/IR/Value.cpp is wrong, a nonnull pointer is not
necessarily dereferenceable.

%a = inttoptr i32 123456 to i32*
call void @foo(i32* %a nonnull)

It's nonnull, but not dereferenceable.

Nick

Luqman Aden wrote:

Added test.

http://reviews.llvm.org/D3389

CHANGE SINCE LAST DIFF

http://reviews.llvm.org/D3389?vs=8552&id=8553#toc

Files:

lib/AsmParser/LLToken.h
lib/AsmParser/LLParser.cpp
lib/AsmParser/LLLexer.cpp
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/Bitcode/Reader/BitcodeReader.cpp
lib/IR/Function.cpp
lib/IR/Attributes.cpp
lib/Analysis/ValueTracking.cpp
test/Bitcode/attributes.ll
test/Analysis/BasicAA/nonnull.ll
include/llvm/Bitcode/LLVMBitCodes.h
include/llvm/IR/Attributes.h
include/llvm/IR/Argument.h

llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

luqmana updated this revision to Unknown Object (????).Apr 18 2014, 8:01 AM

Removed check from isDereferenceablePointer and added Verifier test.

luqmana updated this revision to Unknown Object (????).Apr 18 2014, 7:46 PM

Added docs.

This information could also be used in ArgPromotion::isSafeToPromoteArgument(). Its second argument, isByValOrInAlloca, is used to determine whether a pointer argument is always valid.

dotdash:

This information could also be used in ArgPromotion::isSafeToPromoteArgument(). Its second argument, isByValOrInAlloca, is used to determine whether a pointer argument is always valid.

I don't that would be valid since a nonnull pointer is not necessarily dereferenceable.

luqmana updated this revision to Diff 9400.May 14 2014, 1:27 PM
luqmana added a reviewer: nicholas.
luqmana added a subscriber: nicholas.

Updated to address review comments.

luqmana abandoned this revision.Sep 1 2014, 2:38 PM