Skip to content

Commit

Permalink
[InlineCost] isKnownNonNullInCallee - handle also dereferenceable att…
Browse files Browse the repository at this point in the history
…ribute
  • Loading branch information
davidbolvansky committed Apr 6, 2023
1 parent 91a0740 commit 3b5ff3a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/InlineCost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ bool CallAnalyzer::isKnownNonNullInCallee(Value *V) {
// parameter attribute, but that's a less interesting case because hopefully
// the callee would already have been simplified based on that.
if (Argument *A = dyn_cast<Argument>(V))
if (paramHasAttr(A, Attribute::NonNull))
if (paramHasAttr(A, Attribute::NonNull) || paramHasAttr(A, Attribute::Dereferenceable))
return true;

// Is this an alloca in the caller? This is distinct from the attribute case
Expand Down
22 changes: 20 additions & 2 deletions llvm/test/Transforms/Inline/nonnull.ll
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ define void @caller3(ptr %arg) {
ret void
}

; Positive test - arg is known non null
define void @caller4(ptr dereferenceable(8) %arg) {
; CHECK-LABEL: define void @caller4
; CHECK-SAME: (ptr dereferenceable(8) [[ARG:%.*]]) {
; CHECK-NEXT: call void @callee(ptr dereferenceable(8) [[ARG]])
; CHECK-NEXT: call void @bar()
; CHECK-NEXT: ret void
;
call void @callee(ptr dereferenceable(8) %arg)
Expand All @@ -122,7 +123,24 @@ define void @caller5(ptr dereferenceable(8) %arg) {
define void @caller6(ptr %arg) {
; CHECK-LABEL: define void @caller6
; CHECK-SAME: (ptr [[ARG:%.*]]) {
; CHECK-NEXT: call void @callee(ptr dereferenceable(8) [[ARG]])
; CHECK-NEXT: [[CMP_I:%.*]] = icmp eq ptr [[ARG]], null
; CHECK-NEXT: br i1 [[CMP_I]], label [[EXPENSIVE_I:%.*]], label [[DONE_I:%.*]]
; CHECK: expensive.i:
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: call void @foo()
; CHECK-NEXT: br label [[CALLEE_EXIT:%.*]]
; CHECK: done.i:
; CHECK-NEXT: call void @bar()
; CHECK-NEXT: br label [[CALLEE_EXIT]]
; CHECK: callee.exit:
; CHECK-NEXT: ret void
;
call void @callee(ptr dereferenceable(8) %arg)
Expand Down

0 comments on commit 3b5ff3a

Please sign in to comment.