Skip to content

[FunctionAttrs] Determine underlying object by getUnderlyingObjectAggressive #100102

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 3 commits into from
Jul 23, 2024
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
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void addLocAccess(MemoryEffects &ME, const MemoryLocation &Loc,
if (isNoModRef(MR))
return;

const Value *UO = getUnderlyingObject(Loc.Ptr);
const Value *UO = getUnderlyingObjectAggressive(Loc.Ptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert(!isa<AllocaInst>(UO) &&
"Should have been handled by getModRefInfoMask()");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should convert this into if(isa<AllocaInst>(UO)) return.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I see it in the logs now. It doesn't seem to require additional test cases, so I will submit it directly later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reland with a test case: 559be8e.

if (isa<Argument>(UO)) {
Expand Down
124 changes: 124 additions & 0 deletions llvm/test/Transforms/FunctionAttrs/argmemonly.ll
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,127 @@ define void @test_scc_argmem_read_2(ptr %p) {
call void @test_scc_argmem_read_1(ptr %p)
ret void
}

define i64 @select_same_obj(i1 %c, ptr %p, i64 %x) {
; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
; FNATTRS-LABEL: define i64 @select_same_obj
; FNATTRS-SAME: (i1 [[C:%.*]], ptr nocapture readonly [[P:%.*]], i64 [[X:%.*]]) #[[ATTR1]] {
; FNATTRS-NEXT: entry:
; FNATTRS-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i64 [[X]]
; FNATTRS-NEXT: [[P3:%.*]] = select i1 [[C]], ptr [[P]], ptr [[P2]]
; FNATTRS-NEXT: [[R:%.*]] = load i64, ptr [[P3]], align 4
; FNATTRS-NEXT: ret i64 [[R]]
;
; ATTRIBUTOR: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
; ATTRIBUTOR-LABEL: define i64 @select_same_obj
; ATTRIBUTOR-SAME: (i1 [[C:%.*]], ptr nocapture nofree readonly [[P:%.*]], i64 [[X:%.*]]) #[[ATTR0]] {
; ATTRIBUTOR-NEXT: entry:
; ATTRIBUTOR-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i64 [[X]]
; ATTRIBUTOR-NEXT: [[P3:%.*]] = select i1 [[C]], ptr [[P]], ptr [[P2]]
; ATTRIBUTOR-NEXT: [[R:%.*]] = load i64, ptr [[P3]], align 4
; ATTRIBUTOR-NEXT: ret i64 [[R]]
;
entry:
%p2 = getelementptr i8, ptr %p, i64 %x
%p3 = select i1 %c, ptr %p, ptr %p2
%r = load i64, ptr %p3
ret i64 %r
}

; FIXME: This could be `memory(argmem: read)`.
define i64 @select_different_obj(i1 %c, ptr %p, ptr %p2) {
; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none)
; FNATTRS-LABEL: define i64 @select_different_obj
; FNATTRS-SAME: (i1 [[C:%.*]], ptr nocapture readonly [[P:%.*]], ptr nocapture readonly [[P2:%.*]]) #[[ATTR3]] {
; FNATTRS-NEXT: entry:
; FNATTRS-NEXT: [[P3:%.*]] = select i1 [[C]], ptr [[P]], ptr [[P2]]
; FNATTRS-NEXT: [[R:%.*]] = load i64, ptr [[P3]], align 4
; FNATTRS-NEXT: ret i64 [[R]]
;
; ATTRIBUTOR: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
; ATTRIBUTOR-LABEL: define i64 @select_different_obj
; ATTRIBUTOR-SAME: (i1 [[C:%.*]], ptr nocapture nofree readonly [[P:%.*]], ptr nocapture nofree readonly [[P2:%.*]]) #[[ATTR0]] {
; ATTRIBUTOR-NEXT: entry:
; ATTRIBUTOR-NEXT: [[P3:%.*]] = select i1 [[C]], ptr [[P]], ptr [[P2]]
; ATTRIBUTOR-NEXT: [[R:%.*]] = load i64, ptr [[P3]], align 4
; ATTRIBUTOR-NEXT: ret i64 [[R]]
;
entry:
%p3 = select i1 %c, ptr %p, ptr %p2
%r = load i64, ptr %p3
ret i64 %r
}

define i64 @phi_same_obj(i1 %c, ptr %p, i64 %x) {
; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
; FNATTRS-LABEL: define i64 @phi_same_obj
; FNATTRS-SAME: (i1 [[C:%.*]], ptr nocapture readonly [[P:%.*]], i64 [[X:%.*]]) #[[ATTR1]] {
; FNATTRS-NEXT: entry:
; FNATTRS-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i64 [[X]]
; FNATTRS-NEXT: br i1 [[C]], label [[IF:%.*]], label [[JOIN:%.*]]
; FNATTRS: if:
; FNATTRS-NEXT: br label [[JOIN]]
; FNATTRS: join:
; FNATTRS-NEXT: [[P3:%.*]] = phi ptr [ [[P]], [[IF]] ], [ [[P2]], [[ENTRY:%.*]] ]
; FNATTRS-NEXT: [[R:%.*]] = load i64, ptr [[P3]], align 4
; FNATTRS-NEXT: ret i64 [[R]]
;
; ATTRIBUTOR: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
; ATTRIBUTOR-LABEL: define i64 @phi_same_obj
; ATTRIBUTOR-SAME: (i1 [[C:%.*]], ptr nocapture nofree readonly [[P:%.*]], i64 [[X:%.*]]) #[[ATTR1]] {
; ATTRIBUTOR-NEXT: entry:
; ATTRIBUTOR-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i64 [[X]]
; ATTRIBUTOR-NEXT: br i1 [[C]], label [[IF:%.*]], label [[JOIN:%.*]]
; ATTRIBUTOR: if:
; ATTRIBUTOR-NEXT: br label [[JOIN]]
; ATTRIBUTOR: join:
; ATTRIBUTOR-NEXT: [[P3:%.*]] = phi ptr [ [[P]], [[IF]] ], [ [[P2]], [[ENTRY:%.*]] ]
; ATTRIBUTOR-NEXT: [[R:%.*]] = load i64, ptr [[P3]], align 4
; ATTRIBUTOR-NEXT: ret i64 [[R]]
;
entry:
%p2 = getelementptr i8, ptr %p, i64 %x
br i1 %c, label %if, label %join
if:
br label %join
join:
%p3 = phi ptr [ %p, %if ], [ %p2, %entry ]
%r = load i64, ptr %p3
ret i64 %r
}

; FIXME: This could be `memory(argmem: read)`.
define i64 @phi_different_obj(i1 %c, ptr %p, ptr %p2) {
; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none)
; FNATTRS-LABEL: define i64 @phi_different_obj
; FNATTRS-SAME: (i1 [[C:%.*]], ptr nocapture readonly [[P:%.*]], ptr nocapture readonly [[P2:%.*]]) #[[ATTR3]] {
; FNATTRS-NEXT: entry:
; FNATTRS-NEXT: br i1 [[C]], label [[IF:%.*]], label [[JOIN:%.*]]
; FNATTRS: if:
; FNATTRS-NEXT: br label [[JOIN]]
; FNATTRS: join:
; FNATTRS-NEXT: [[P3:%.*]] = phi ptr [ [[P]], [[IF]] ], [ [[P2]], [[ENTRY:%.*]] ]
; FNATTRS-NEXT: [[R:%.*]] = load i64, ptr [[P3]], align 4
; FNATTRS-NEXT: ret i64 [[R]]
;
; ATTRIBUTOR: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
; ATTRIBUTOR-LABEL: define i64 @phi_different_obj
; ATTRIBUTOR-SAME: (i1 [[C:%.*]], ptr nocapture nofree readonly [[P:%.*]], ptr nocapture nofree readonly [[P2:%.*]]) #[[ATTR1]] {
; ATTRIBUTOR-NEXT: entry:
; ATTRIBUTOR-NEXT: br i1 [[C]], label [[IF:%.*]], label [[JOIN:%.*]]
; ATTRIBUTOR: if:
; ATTRIBUTOR-NEXT: br label [[JOIN]]
; ATTRIBUTOR: join:
; ATTRIBUTOR-NEXT: [[P3:%.*]] = phi ptr [ [[P]], [[IF]] ], [ [[P2]], [[ENTRY:%.*]] ]
; ATTRIBUTOR-NEXT: [[R:%.*]] = load i64, ptr [[P3]], align 4
; ATTRIBUTOR-NEXT: ret i64 [[R]]
;
entry:
br i1 %c, label %if, label %join
if:
br label %join
join:
%p3 = phi ptr [ %p, %if ], [ %p2, %entry ]
%r = load i64, ptr %p3
ret i64 %r
}
Loading