1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[InstCombine] Don't coerce non-integral pointers to integers

Reviewers: majnemer

Subscribers: mcrosier, llvm-commits

Differential Revision: https://reviews.llvm.org/D23231

llvm-svn: 277910
This commit is contained in:
Sanjoy Das 2016-08-06 02:58:48 +00:00
parent 61a94e86f0
commit aca3962ed4
3 changed files with 35 additions and 1 deletions

View File

@ -338,6 +338,11 @@ public:
NonIntegralSpaces.end();
}
bool isNonIntegralPointerType(Type *Ty) const {
auto *PTy = dyn_cast<PointerType>(Ty);
return PTy && isNonIntegralPointerType(PTy);
}
/// Layout pointer size, in bits
/// FIXME: The defaults need to be removed once all of
/// the backends/clients are updated.

View File

@ -475,7 +475,8 @@ static Instruction *combineLoadToOperationType(InstCombiner &IC, LoadInst &LI) {
// size is a legal integer type.
if (!Ty->isIntegerTy() && Ty->isSized() &&
DL.isLegalInteger(DL.getTypeStoreSizeInBits(Ty)) &&
DL.getTypeStoreSizeInBits(Ty) == DL.getTypeSizeInBits(Ty)) {
DL.getTypeStoreSizeInBits(Ty) == DL.getTypeSizeInBits(Ty) &&
!DL.isNonIntegralPointerType(Ty)) {
if (std::all_of(LI.user_begin(), LI.user_end(), [&LI](User *U) {
auto *SI = dyn_cast<StoreInst>(U);
return SI && SI->getPointerOperand() != &LI;

View File

@ -18,3 +18,31 @@ define i8 addrspace(3)* @f_1() {
%result = getelementptr i8, i8 addrspace(3)* null, i64 50
ret i8 addrspace(3)* %result
}
define void @f_2(i8 addrspace(4)** %ptr0, i8 addrspace(4)** %ptr1) {
; It is not okay to convert the load/store pair to load and store
; integers, since pointers in address space 4 are non-integral.
; CHECK-LABEL: @f_2(
entry:
; CHECK: %val = load i8 addrspace(4)*, i8 addrspace(4)** %ptr0, align 8
; CHECK: store i8 addrspace(4)* %val, i8 addrspace(4)** %ptr1, align 8
; CHECK-NOT: load i64
; CHECK-NOT: store i64
%val = load i8 addrspace(4)*, i8 addrspace(4)** %ptr0
store i8 addrspace(4)* %val, i8 addrspace(4)** %ptr1
ret void
}
define void @f_3(i8 addrspace(3)** %ptr0, i8 addrspace(3)** %ptr1) {
; It *is* okay to convert the load/store pair to load and store
; integers, since pointers in address space 3 are integral.
; CHECK-LABEL: @f_3(
entry:
; CHECK: load i64
; CHECK: store i64
%val = load i8 addrspace(3)*, i8 addrspace(3)** %ptr0
store i8 addrspace(3)* %val, i8 addrspace(3)** %ptr1
ret void
}