Skip to content

Commit

Permalink
[ValueTracking] Dereferenceable ret attributes implys noundef
Browse files Browse the repository at this point in the history
Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D156510
  • Loading branch information
luxufan committed Aug 7, 2023
1 parent bcfdb3e commit 4e84ec8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6757,7 +6757,9 @@ static bool isGuaranteedNotToBeUndefOrPoison(const Value *V,
return true;

if (const auto *CB = dyn_cast<CallBase>(V)) {
if (CB->hasRetAttr(Attribute::NoUndef))
if (CB->hasRetAttr(Attribute::NoUndef) ||
CB->hasRetAttr(Attribute::Dereferenceable) ||
CB->hasRetAttr(Attribute::DereferenceableOrNull))
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/Attributor/memory_locations.ll
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ define dso_local ptr @internal_argmem_only_write(ptr %arg) {
; CHECK-SAME: (ptr nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[ARG:%.*]]) #[[ATTR1]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: store i32 10, ptr [[ARG]], align 4
; CHECK-NEXT: [[CALL:%.*]] = call noalias dereferenceable_or_null(10) ptr @malloc(i64 noundef 10)
; CHECK-NEXT: [[CALL:%.*]] = call noalias noundef dereferenceable_or_null(10) ptr @malloc(i64 noundef 10)
; CHECK-NEXT: ret ptr [[CALL]]
;
entry:
Expand Down

0 comments on commit 4e84ec8

Please sign in to comment.