Skip to content

Commit

Permalink
[CallSiteSplit] Make sure we remove nonnull if the parameter turns ou…
Browse files Browse the repository at this point in the history
…t to be a constant.

Summary: We do not need nonull attribute if we know an argument is going to be constant.

Reviewers: junbuml, davide, fhahn

Subscribers: llvm-commits

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

llvm-svn: 330641
  • Loading branch information
trentxintong committed Apr 23, 2018
1 parent 1a2ce57 commit 8edff27
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp
Expand Up @@ -97,8 +97,12 @@ static void setConstantInArgument(CallSite CS, Value *Op,
Constant *ConstValue) {
unsigned ArgNo = 0;
for (auto &I : CS.args()) {
if (&*I == Op)
if (&*I == Op) {
// It is possible we have already added the non-null attribute to the
// parameter by using an earlier constraining condition.
CS.removeParamAttr(ArgNo, Attribute::NonNull);
CS.setArgument(ArgNo, ConstValue);
}
++ArgNo;
}
}
Expand Down
29 changes: 29 additions & 0 deletions llvm/test/Transforms/CallSiteSplitting/callsite-split-or-phi.ll
Expand Up @@ -532,3 +532,32 @@ End:

declare void @dummy(i32*, i32)
declare void @dummy2(i32, i32)

; Make sure we remove the non-nullness on constant paramater.
;
;CHECK-LABEL: @caller2
;CHECK-LABEL: Top1.split:
;CHECK: call i32 @callee(i32* inttoptr (i64 4643 to i32*)
define void @caller2(i32 %c, i32* %a_elt, i32* %b_elt) {
entry:
br label %Top0

Top0:
%tobool1 = icmp eq i32* %a_elt, inttoptr (i64 4643 to i32*)
br i1 %tobool1, label %Top1, label %NextCond

Top1:
%tobool2 = icmp ne i32* %a_elt, null
br i1 %tobool2, label %CallSiteBB, label %NextCond

NextCond:
%cmp = icmp ne i32* %b_elt, null
br i1 %cmp, label %CallSiteBB, label %End

CallSiteBB:
call i32 @callee(i32* %a_elt, i32 %c, i32 %c)
br label %End

End:
ret void
}

0 comments on commit 8edff27

Please sign in to comment.