Skip to content

[InferAddressSpaces] collect flat address expression from return value #70610

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 2 commits into from
Nov 1, 2023
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
4 changes: 4 additions & 0 deletions llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ InferAddressSpacesImpl::collectFlatAddressExpressions(Function &F) const {
} else if (auto *I2P = dyn_cast<IntToPtrInst>(&I)) {
if (isNoopPtrIntCastPair(cast<Operator>(I2P), *DL, TTI))
PushPtrOperand(cast<Operator>(I2P->getOperand(0))->getOperand(0));
} else if (auto *RI = dyn_cast<ReturnInst>(&I)) {
if (auto *RV = RI->getReturnValue();
RV && RV->getType()->isPtrOrPtrVectorTy())
PushPtrOperand(RV);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ define ptr @noop_ptrint_pair_ce2() {
ret ptr inttoptr (i64 ptrtoint (ptr addrspace(1) @g to i64) to ptr)
}

; COMMON-LABEL: @noop_ptrint_pair_ce2_vec(
; AMDGCN-NEXT: ret <2 x ptr> <ptr addrspacecast (ptr addrspace(1) @g to ptr), ptr inttoptr (i64 ptrtoint (ptr addrspace(3) @l to i64) to ptr)>
; NOTTI-NEXT: ret <2 x ptr> <ptr inttoptr (i64 ptrtoint (ptr addrspace(1) @g to i64) to ptr), ptr inttoptr (i64 ptrtoint (ptr addrspace(3) @l to i64) to ptr)>
define <2 x ptr> @noop_ptrint_pair_ce2_vec() {
ret <2 x ptr> <ptr inttoptr (i64 ptrtoint (ptr addrspace(1) @g to i64) to ptr), ptr inttoptr (i64 ptrtoint (ptr addrspace(3) @l to i64) to ptr)>
}

; COMMON-LABEL: @noop_ptrint_pair_ce3(
; AMDGCN-NEXT: %i = inttoptr i64 ptrtoint (ptr addrspace(1) @g to i64) to ptr
; AMDGCN-NEXT: ret void
Expand Down
10 changes: 5 additions & 5 deletions llvm/test/Transforms/InferAddressSpaces/AMDGPU/select.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
; Instcombine pulls the addrspacecast out of the select, make sure
; this doesn't do something insane on non-canonical IR.

; CHECK-LABEL: @return_select_group_flat(
; CHECK-NEXT: %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this also should check the signature of the function; need to make sure you aren't mutating it in a way that breaks uses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

; CHECK-NEXT: %cast1 = addrspacecast ptr addrspace(3) %group.ptr.1 to ptr
; CHECK-NEXT: %select = select i1 %c, ptr %cast0, ptr %cast1
; CHECK-NEXT: ret ptr %select
; CHECK-LABEL: define ptr @return_select_group_flat(
; CHECK-SAME: i1 [[C:%.*]], ptr addrspace(3) [[GROUP_PTR_0:%.*]], ptr addrspace(3) [[GROUP_PTR_1:%.*]]) #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[C]], ptr addrspace(3) [[GROUP_PTR_0]], ptr addrspace(3) [[GROUP_PTR_1]]
; CHECK-NEXT: [[TMP1:%.*]] = addrspacecast ptr addrspace(3) [[SELECT]] to ptr
; CHECK-NEXT: ret ptr [[TMP1]]
define ptr @return_select_group_flat(i1 %c, ptr addrspace(3) %group.ptr.0, ptr addrspace(3) %group.ptr.1) #0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add a test with a vector of pointers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added noop_ptrint_pair_ce2_vec to noop-ptrint-pair.ll
I find that currently isAddressExpression isn't handling ConstantAggregate so vector of pointers is not inferred. The change at line 73 of bca6a66 is just because currently constant is replaced globally, i.e. it is replaced while handling another function.

%cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
%cast1 = addrspacecast ptr addrspace(3) %group.ptr.1 to ptr
Expand Down