[llvm] d199ff1 - [InferAddressSpaces] collect flat address expression from return value (#70610)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 31 22:32:42 PDT 2023
Author: Wenju He
Date: 2023-11-01T13:32:38+08:00
New Revision: d199ff17659fc65a9b1b4ebe2d304cdbfdfe89d7
URL: https://github.com/llvm/llvm-project/commit/d199ff17659fc65a9b1b4ebe2d304cdbfdfe89d7
DIFF: https://github.com/llvm/llvm-project/commit/d199ff17659fc65a9b1b4ebe2d304cdbfdfe89d7.diff
LOG: [InferAddressSpaces] collect flat address expression from return value (#70610)
If function return value's type is pointer, we can try to collect flat
address expression from it.
This PR also fixes noop_ptrint_pair_ce2 in noop-ptrint-pair.ll in #70611
Added:
Modified:
llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll
llvm/test/Transforms/InferAddressSpaces/AMDGPU/select.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
index 2da521375c00161..28fe1b5e75327e6 100644
--- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -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);
}
}
diff --git a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll
index a73cd517fd49d5a..b6713e96bed3ff5 100644
--- a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll
+++ b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll
@@ -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
diff --git a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/select.ll b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/select.ll
index 9495c5566b36c2a..ab4e1277b81fdbd 100644
--- a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/select.ll
+++ b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/select.ll
@@ -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
-; 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 {
%cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
%cast1 = addrspacecast ptr addrspace(3) %group.ptr.1 to ptr
More information about the llvm-commits
mailing list