Skip to content

Commit 5b59246

Browse files
committed
[SimplifyCFG] Switch to use paramHasNonNullAttr
1 parent 2a3afa2 commit 5b59246

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,11 @@ class CallBase : public Instruction {
18391839
/// Extract the number of dereferenceable bytes for a call or
18401840
/// parameter (0=unknown).
18411841
uint64_t getParamDereferenceableBytes(unsigned i) const {
1842-
return Attrs.getParamDereferenceableBytes(i);
1842+
uint64_t Bytes = Attrs.getParamDereferenceableBytes(i);
1843+
if (const Function *F = getCalledFunction())
1844+
Bytes =
1845+
std::max(Bytes, F->getAttributes().getParamDereferenceableBytes(i));
1846+
return Bytes;
18431847
}
18441848

18451849
/// Extract the number of dereferenceable_or_null bytes for a call
@@ -1857,7 +1861,11 @@ class CallBase : public Instruction {
18571861
/// Extract the number of dereferenceable_or_null bytes for a
18581862
/// parameter (0=unknown).
18591863
uint64_t getParamDereferenceableOrNullBytes(unsigned i) const {
1860-
return Attrs.getParamDereferenceableOrNullBytes(i);
1864+
uint64_t Bytes = Attrs.getParamDereferenceableOrNullBytes(i);
1865+
if (const Function *F = getCalledFunction())
1866+
Bytes = std::max(
1867+
Bytes, F->getAttributes().getParamDereferenceableOrNullBytes(i));
1868+
return Bytes;
18611869
}
18621870

18631871
/// Extract a test mask for disallowed floating-point value classes for the

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8224,8 +8224,8 @@ static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValu
82248224
if (CB->isArgOperand(&Use)) {
82258225
unsigned ArgIdx = CB->getArgOperandNo(&Use);
82268226
// Passing null to a nonnnull+noundef argument is undefined.
8227-
if (C->isNullValue() && CB->isPassingUndefUB(ArgIdx) &&
8228-
CB->paramHasAttr(ArgIdx, Attribute::NonNull))
8227+
if (isa<ConstantPointerNull>(C) &&
8228+
CB->paramHasNonNullAttr(ArgIdx, /*AllowUndefOrPoison=*/false))
82298229
return !PtrValueMayBeModified;
82308230
// Passing undef to a noundef argument is undefined.
82318231
if (isa<UndefValue>(C) && CB->isPassingUndefUB(ArgIdx))

llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ else:
238238
}
239239

240240
declare ptr @fn_nonnull_noundef_arg(ptr nonnull noundef %p)
241-
declare ptr @fn_nonnull_deref_arg(ptr nonnull dereferenceable(4) %p)
241+
declare ptr @fn_deref_arg(ptr dereferenceable(4) %p)
242242
declare ptr @fn_nonnull_deref_or_null_arg(ptr nonnull dereferenceable_or_null(4) %p)
243243
declare ptr @fn_nonnull_arg(ptr nonnull %p)
244244
declare ptr @fn_noundef_arg(ptr noundef %p)
@@ -271,7 +271,7 @@ define void @test9_deref(i1 %X, ptr %Y) {
271271
; CHECK-NEXT: entry:
272272
; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[X:%.*]], true
273273
; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
274-
; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_nonnull_deref_arg(ptr [[Y:%.*]])
274+
; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_deref_arg(ptr [[Y:%.*]])
275275
; CHECK-NEXT: ret void
276276
;
277277
entry:
@@ -282,17 +282,16 @@ if:
282282

283283
else:
284284
%phi = phi ptr [ %Y, %entry ], [ null, %if ]
285-
call ptr @fn_nonnull_deref_arg(ptr %phi)
285+
call ptr @fn_deref_arg(ptr %phi)
286286
ret void
287287
}
288288

289289
; Optimizing this code should produce assume.
290290
define void @test9_deref_or_null(i1 %X, ptr %Y) {
291291
; CHECK-LABEL: @test9_deref_or_null(
292292
; CHECK-NEXT: entry:
293-
; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[X:%.*]], true
294-
; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
295-
; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_nonnull_deref_or_null_arg(ptr [[Y:%.*]])
293+
; CHECK-NEXT: [[Y:%.*]] = select i1 [[X:%.*]], ptr null, ptr [[Y1:%.*]]
294+
; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_nonnull_deref_or_null_arg(ptr [[Y]])
296295
; CHECK-NEXT: ret void
297296
;
298297
entry:

0 commit comments

Comments
 (0)