forked from OSchip/llvm-project
Recommit [SROA] Enhance SROA to handle `addrspacecast`ed allocas
[SROA] Enhance SROA to handle `addrspacecast`ed allocas - Fix typo in original change - Add additional handling to ensure all return pointers are properly casted. Summary: - 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. Reviewers: arsenm Subscribers: wdng, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63501 llvm-svn: 363743
This commit is contained in:
parent
7bfb43985f
commit
4f7f70e262
|
@ -1589,6 +1589,12 @@ static Value *getAdjustedPtr(IRBuilderTy &IRB, const DataLayout &DL, Value *Ptr,
|
||||||
PointerType *TargetPtrTy = cast<PointerType>(PointerTy);
|
PointerType *TargetPtrTy = cast<PointerType>(PointerTy);
|
||||||
Type *TargetTy = TargetPtrTy->getElementType();
|
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 = TargetTy->getPointerTo(AS);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// First fold any existing GEPs into the offset.
|
// First fold any existing GEPs into the offset.
|
||||||
while (GEPOperator *GEP = dyn_cast<GEPOperator>(Ptr)) {
|
while (GEPOperator *GEP = dyn_cast<GEPOperator>(Ptr)) {
|
||||||
|
@ -1617,7 +1623,7 @@ static Value *getAdjustedPtr(IRBuilderTy &IRB, const DataLayout &DL, Value *Ptr,
|
||||||
OffsetBasePtr = Ptr;
|
OffsetBasePtr = Ptr;
|
||||||
// If we also found a pointer of the right type, we're done.
|
// If we also found a pointer of the right type, we're done.
|
||||||
if (P->getType() == PointerTy)
|
if (P->getType() == PointerTy)
|
||||||
return P;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stash this pointer if we've found an i8*.
|
// Stash this pointer if we've found an i8*.
|
||||||
|
|
|
@ -299,6 +299,21 @@ define void @select_addrspacecast_gv(i1 %a, i1 %b) {
|
||||||
ret void
|
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}
|
!0 = !{!1, !1, i64 0, i64 1}
|
||||||
!1 = !{!2, i64 1, !"type_0"}
|
!1 = !{!2, i64 1, !"type_0"}
|
||||||
!2 = !{!"root"}
|
!2 = !{!"root"}
|
||||||
|
|
Loading…
Reference in New Issue