Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions llvm/include/llvm/IR/InstrTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,11 @@ class CallBase : public Instruction {
/// Extract the number of dereferenceable bytes for a call or
/// parameter (0=unknown).
uint64_t getParamDereferenceableBytes(unsigned i) const {
return Attrs.getParamDereferenceableBytes(i);
uint64_t Bytes = Attrs.getParamDereferenceableBytes(i);
if (const Function *F = getCalledFunction())
Bytes =
std::max(Bytes, F->getAttributes().getParamDereferenceableBytes(i));
return Bytes;
}

/// Extract the number of dereferenceable_or_null bytes for a call
Expand All @@ -1857,7 +1861,11 @@ class CallBase : public Instruction {
/// Extract the number of dereferenceable_or_null bytes for a
/// parameter (0=unknown).
uint64_t getParamDereferenceableOrNullBytes(unsigned i) const {
return Attrs.getParamDereferenceableOrNullBytes(i);
uint64_t Bytes = Attrs.getParamDereferenceableOrNullBytes(i);
if (const Function *F = getCalledFunction())
Bytes = std::max(
Bytes, F->getAttributes().getParamDereferenceableOrNullBytes(i));
return Bytes;
}

/// Extract a test mask for disallowed floating-point value classes for the
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8224,8 +8224,8 @@ static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValu
if (CB->isArgOperand(&Use)) {
unsigned ArgIdx = CB->getArgOperandNo(&Use);
// Passing null to a nonnnull+noundef argument is undefined.
if (C->isNullValue() && CB->isPassingUndefUB(ArgIdx) &&
CB->paramHasAttr(ArgIdx, Attribute::NonNull))
if (isa<ConstantPointerNull>(C) &&
CB->paramHasNonNullAttr(ArgIdx, /*AllowUndefOrPoison=*/false))
return !PtrValueMayBeModified;
// Passing undef to a noundef argument is undefined.
if (isa<UndefValue>(C) && CB->isPassingUndefUB(ArgIdx))
Expand Down
11 changes: 5 additions & 6 deletions llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ else:
}

declare ptr @fn_nonnull_noundef_arg(ptr nonnull noundef %p)
declare ptr @fn_nonnull_deref_arg(ptr nonnull dereferenceable(4) %p)
declare ptr @fn_deref_arg(ptr dereferenceable(4) %p)
declare ptr @fn_nonnull_deref_or_null_arg(ptr nonnull dereferenceable_or_null(4) %p)
declare ptr @fn_nonnull_arg(ptr nonnull %p)
declare ptr @fn_noundef_arg(ptr noundef %p)
Expand Down Expand Up @@ -271,7 +271,7 @@ define void @test9_deref(i1 %X, ptr %Y) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[X:%.*]], true
; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_nonnull_deref_arg(ptr [[Y:%.*]])
; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_deref_arg(ptr [[Y:%.*]])
; CHECK-NEXT: ret void
;
entry:
Expand All @@ -282,17 +282,16 @@ if:

else:
%phi = phi ptr [ %Y, %entry ], [ null, %if ]
call ptr @fn_nonnull_deref_arg(ptr %phi)
call ptr @fn_deref_arg(ptr %phi)
ret void
}

; Optimizing this code should produce assume.
define void @test9_deref_or_null(i1 %X, ptr %Y) {
; CHECK-LABEL: @test9_deref_or_null(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[X:%.*]], true
; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_nonnull_deref_or_null_arg(ptr [[Y:%.*]])
; CHECK-NEXT: [[Y:%.*]] = select i1 [[X:%.*]], ptr null, ptr [[Y1:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_nonnull_deref_or_null_arg(ptr [[Y]])
; CHECK-NEXT: ret void
;
entry:
Expand Down
Loading