Skip to content

Commit 8b8ce48

Browse files
committed
Simplify the solution by just dropping the dereferenceable attrs
when there is a risk that they would become incorrect if neither adjusting nor dropping them.
1 parent f6f7025 commit 8b8ce48

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,11 +1559,6 @@ class CallBase : public Instruction {
15591559
Attrs = Attrs.addDereferenceableParamAttr(getContext(), i, Bytes);
15601560
}
15611561

1562-
/// adds the dereferenceable attribute to the list of attributes.
1563-
void addDereferenceableOrNullParamAttr(unsigned i, uint64_t Bytes) {
1564-
Attrs = Attrs.addDereferenceableOrNullParamAttr(getContext(), i, Bytes);
1565-
}
1566-
15671562
/// adds the dereferenceable attribute to the list of attributes.
15681563
void addDereferenceableRetAttr(uint64_t Bytes) {
15691564
Attrs = Attrs.addDereferenceableRetAttr(getContext(), Bytes);

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -563,22 +563,6 @@ static void shortenAssignment(Instruction *Inst, Value *OriginalDest,
563563
for_each(LinkedDVRAssigns, InsertAssignForOverlap);
564564
}
565565

566-
// Helper to trim or drop any dereferencable/dereferencable_or_null attributes
567-
// for a given argument, based on the new access being restricted to derefence
568-
// bytes in the range [Offset, Offset+Size).
569-
static void trimDereferencableAttrs(AnyMemIntrinsic *Intrinsic, unsigned Arg,
570-
uint64_t Offset, uint64_t Size) {
571-
uint64_t End = Offset + Size;
572-
if (Intrinsic->getParamDereferenceableBytes(Arg) >= End)
573-
Intrinsic->addDereferenceableParamAttr(Arg, Size);
574-
else
575-
Intrinsic->removeParamAttr(Arg, Attribute::Dereferenceable);
576-
if (Intrinsic->getParamDereferenceableOrNullBytes(Arg) >= End)
577-
Intrinsic->addDereferenceableOrNullParamAttr(Arg, Size);
578-
else
579-
Intrinsic->removeParamAttr(Arg, Attribute::DereferenceableOrNull);
580-
}
581-
582566
static bool tryToShorten(Instruction *DeadI, int64_t &DeadStart,
583567
uint64_t &DeadSize, int64_t KillingStart,
584568
uint64_t KillingSize, bool IsOverwriteEnd) {
@@ -660,7 +644,11 @@ static bool tryToShorten(Instruction *DeadI, int64_t &DeadStart,
660644
DeadI->getIterator());
661645
NewDestGEP->setDebugLoc(DeadIntrinsic->getDebugLoc());
662646
DeadIntrinsic->setDest(NewDestGEP);
663-
trimDereferencableAttrs(DeadIntrinsic, 0, ToRemoveSize, NewSize);
647+
// Simply drop any dereferenceable attributes (memset with a constant length
648+
// already implies dereferenceability by itself, so dropping is simpler than
649+
// trying to adjust the dereferenceable size).
650+
DeadIntrinsic->removeParamAttr(0, Attribute::Dereferenceable);
651+
DeadIntrinsic->removeParamAttr(0, Attribute::DereferenceableOrNull);
664652
}
665653

666654
// Update attached dbg.assign intrinsics. Assume 8-bit byte.

llvm/test/Transforms/DeadStoreElimination/OverwriteStoreBegin.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,12 @@ entry:
403403
ret void
404404
}
405405

406-
; Verify that we adjust the dereferenceable attribute.
406+
; Verify that we adjust/drop the dereferenceable attribute.
407407
define void @dereferenceable(ptr nocapture %p) {
408408
; CHECK-LABEL: @dereferenceable(
409409
; CHECK-NEXT: entry:
410410
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 4
411-
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 dereferenceable(24) [[TMP0]], i8 0, i64 24, i1 false)
411+
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[TMP0]], i8 0, i64 24, i1 false)
412412
; CHECK-NEXT: store i32 1, ptr [[P]], align 4
413413
; CHECK-NEXT: ret void
414414
;
@@ -418,12 +418,12 @@ entry:
418418
ret void
419419
}
420420

421-
; Verify that we adjust the dereferenceable_or_null attribute.
421+
; Verify that we adjust/drop the dereferenceable_or_null attribute.
422422
define void @dereferenceable_or_null(ptr nocapture %p) {
423423
; CHECK-LABEL: @dereferenceable_or_null(
424424
; CHECK-NEXT: entry:
425425
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 8
426-
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 dereferenceable_or_null(20) [[TMP0]], i8 0, i64 20, i1 false)
426+
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[TMP0]], i8 0, i64 20, i1 false)
427427
; CHECK-NEXT: store i64 1, ptr [[P]], align 4
428428
; CHECK-NEXT: ret void
429429
;

0 commit comments

Comments
 (0)