Skip to content

[MemoryLocation] Teach MemoryLocation about llvm.experimental.memset.pattern #120421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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: 12 additions & 0 deletions llvm/lib/Analysis/MemoryLocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ MemoryLocation MemoryLocation::getForArgument(const CallBase *Call,
AATags);
return MemoryLocation::getAfter(Arg, AATags);

case Intrinsic::experimental_memset_pattern:
assert((ArgIdx == 0 || ArgIdx == 1) &&
"Invalid argument index for memory intrinsic");
if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getArgOperand(2)))
return MemoryLocation(
Arg,
LocationSize::precise(
LenCI->getZExtValue() *
DL.getTypeAllocSize(II->getArgOperand(1)->getType())),
AATags);
return MemoryLocation::getAfter(Arg, AATags);

case Intrinsic::lifetime_start:
case Intrinsic::lifetime_end:
case Intrinsic::invariant_start:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Analysis/BasicAA/memset-pattern.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ define void @test_memset_pattern4_const_size(ptr noalias %a, i32 %pattern) {
; CHECK-LABEL: Function: test_memset_pattern4_const_size
; CHECK: Just Mod: Ptr: i8* %a <-> call void @llvm.experimental.memset.pattern.p0.i32.i64(ptr %a, i32 %pattern, i64 17, i1 false)
; CHECK-NEXT: Just Mod: Ptr: i8* %a.gep.1 <-> call void @llvm.experimental.memset.pattern.p0.i32.i64(ptr %a, i32 %pattern, i64 17, i1 false)
; CHECK-NEXT: Just Mod: Ptr: i8* %a.gep.129 <-> call void @llvm.experimental.memset.pattern.p0.i32.i64(ptr %a, i32 %pattern, i64 17, i1 false)
; CHECK-NEXT: NoModRef: Ptr: i8* %a.gep.129 <-> call void @llvm.experimental.memset.pattern.p0.i32.i64(ptr %a, i32 %pattern, i64 17, i1 false)

entry:
load i8, ptr %a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ define void @memset_pattern_and_store_2(ptr %ptr, i64 %len) {

define void @memset_pattern_and_store_3(ptr %ptr) {
; CHECK-LABEL: @memset_pattern_and_store_3(
; CHECK-NEXT: store i64 0, ptr [[PTR:%.*]], align 4
; CHECK-NEXT: call void @llvm.experimental.memset.pattern.p0.i8.i64(ptr align 1 [[PTR]], i8 0, i64 13, i1 false)
; CHECK-NEXT: call void @llvm.experimental.memset.pattern.p0.i8.i64(ptr align 1 [[PTR:%.*]], i8 0, i64 13, i1 false)
; CHECK-NEXT: ret void
;
store i64 0, ptr %ptr
Expand Down
Loading