[PATCH] D63501: [SROA] Enhance SROA to handle `addrspacecast`ed allocas
Michael Liao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 18 10:13:20 PDT 2019
hliao created this revision.
hliao added a reviewer: arsenm.
Herald added subscribers: llvm-commits, hiraditya, wdng.
Herald added a project: LLVM.
- After `addrspacecast` is allowed to be eliminated in SROA, the adjusting of storage pointer (from `alloca) needs to handle the potential different address spaces between the storage pointer (from alloca) and the pointer being used.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D63501
Files:
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/Transforms/SROA/addrspacecast.ll
Index: llvm/test/Transforms/SROA/addrspacecast.ll
===================================================================
--- llvm/test/Transforms/SROA/addrspacecast.ll
+++ llvm/test/Transforms/SROA/addrspacecast.ll
@@ -299,6 +299,21 @@
ret void
}
+; CHECK-LABEL: @select_addrspacecast_i8(
+; CHECK: [[SEL:%.*]] = select i1 undef, i8 undef, i8 undef
+; CHECK-NEXT: ret i8 [[SEL]]
+define i8 @select_addrspacecast_i8() {
+ %a = alloca i8
+ %b = alloca i8
+
+ %a.ptr = addrspacecast i8* %a to i8 addrspace(1)*
+ %b.ptr = addrspacecast i8* %b to i8 addrspace(1)*
+
+ %ptr = select i1 undef, i8 addrspace(1)* %a.ptr, i8 addrspace(1)* %b.ptr
+ %ret = load i8, i8 addrspace(1)* %ptr
+ ret i8 %ret
+}
+
!0 = !{!1, !1, i64 0, i64 1}
!1 = !{!2, i64 1, !"type_0"}
!2 = !{!"root"}
Index: llvm/lib/Transforms/Scalar/SROA.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SROA.cpp
+++ llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1589,6 +1589,12 @@
PointerType *TargetPtrTy = cast<PointerType>(PointerTy);
Type *TargetTy = TargetPtrTy->getElementType();
+ // As `addrspacecast` is , `Ptr` (the storage pointer) may have different
+ // address space from the expected `PointerTy` (the pointer to be used).
+ // Adjust the pointer type based the original storage pointer.
+ auto AS = cast<PointerType>(Ptr->getType())->getAddressSpace();
+ PointerTy = PointerTy->getPointerTo(AS);
+
do {
// First fold any existing GEPs into the offset.
while (GEPOperator *GEP = dyn_cast<GEPOperator>(Ptr)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63501.205386.patch
Type: text/x-patch
Size: 1564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190618/01d9147d/attachment.bin>
More information about the llvm-commits
mailing list