[llvm] [InferAddressSpaces] collect flat address expression from return value (PR #70610)
Wenju He via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 29 17:28:56 PDT 2023
https://github.com/wenju-he created https://github.com/llvm/llvm-project/pull/70610
If function return value's type is pointer, we can try to collect flat
address expression from it.
>From 5b18d81d915b923556047adb811f38d326ccf820 Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Mon, 30 Oct 2023 08:17:47 +0800
Subject: [PATCH] [InferAddressSpaces] collect flat address expression from
return value
If function return value's type is pointer, we can try to collect flat
address expression from it.
---
llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp | 4 ++++
llvm/test/Transforms/InferAddressSpaces/AMDGPU/select.ll | 7 +++----
2 files changed, 7 insertions(+), 4 deletions(-)
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/select.ll b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/select.ll
index 9495c5566b36c2a..150577e41818909 100644
--- a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/select.ll
+++ b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/select.ll
@@ -4,10 +4,9 @@
; 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-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