mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[OpaquePtr] Support changing load type in InstCombine
When the load type is changed to ptr, we need the load pointer type to also be ptr, because it's not allowed to create a pointer to an opaque pointer. This is achieved by adjusting the getPointerTo() API to return an opaque pointer for an opaque pointer base type. Differential Revision: https://reviews.llvm.org/D104718
This commit is contained in:
parent
d90334b511
commit
09e246902d
@ -483,6 +483,7 @@ public:
|
||||
|
||||
/// Return a pointer to the current type. This is equivalent to
|
||||
/// PointerType::get(Foo, AddrSpace).
|
||||
/// TODO: Remove this after opaque pointer transition is complete.
|
||||
PointerType *getPointerTo(unsigned AddrSpace = 0) const;
|
||||
|
||||
private:
|
||||
|
@ -725,8 +725,13 @@ PointerType::PointerType(LLVMContext &C, unsigned AddrSpace)
|
||||
setSubclassData(AddrSpace);
|
||||
}
|
||||
|
||||
PointerType *Type::getPointerTo(unsigned addrs) const {
|
||||
return PointerType::get(const_cast<Type*>(this), addrs);
|
||||
PointerType *Type::getPointerTo(unsigned AddrSpace) const {
|
||||
// Pointer to opaque pointer is opaque pointer.
|
||||
if (auto *PTy = dyn_cast<PointerType>(this))
|
||||
if (PTy->isOpaque())
|
||||
return PointerType::get(getContext(), AddrSpace);
|
||||
|
||||
return PointerType::get(const_cast<Type*>(this), AddrSpace);
|
||||
}
|
||||
|
||||
bool PointerType::isValidElementType(Type *ElemTy) {
|
||||
|
@ -463,11 +463,11 @@ LoadInst *InstCombinerImpl::combineLoadToNewType(LoadInst &LI, Type *NewTy,
|
||||
|
||||
Value *Ptr = LI.getPointerOperand();
|
||||
unsigned AS = LI.getPointerAddressSpace();
|
||||
Type *NewPtrTy = NewTy->getPointerTo(AS);
|
||||
Value *NewPtr = nullptr;
|
||||
if (!(match(Ptr, m_BitCast(m_Value(NewPtr))) &&
|
||||
NewPtr->getType()->getPointerElementType() == NewTy &&
|
||||
NewPtr->getType()->getPointerAddressSpace() == AS))
|
||||
NewPtr = Builder.CreateBitCast(Ptr, NewTy->getPointerTo(AS));
|
||||
NewPtr->getType() == NewPtrTy))
|
||||
NewPtr = Builder.CreateBitCast(Ptr, NewPtrTy);
|
||||
|
||||
LoadInst *NewLoad = Builder.CreateAlignedLoad(
|
||||
NewTy, NewPtr, LI.getAlign(), LI.isVolatile(), LI.getName() + Suffix);
|
||||
|
@ -87,3 +87,24 @@ define ptr @gep_constexpr_2(ptr %a) {
|
||||
;
|
||||
ret ptr getelementptr (i8, ptr bitcast (i8* @g to ptr), i32 3)
|
||||
}
|
||||
|
||||
define ptr @load_bitcast_1(ptr %a) {
|
||||
; CHECK-LABEL: @load_bitcast_1(
|
||||
; CHECK-NEXT: [[B1:%.*]] = load ptr, ptr [[A:%.*]], align 8
|
||||
; CHECK-NEXT: ret ptr [[B1]]
|
||||
;
|
||||
%b = load i8*, ptr %a
|
||||
%c = bitcast i8* %b to ptr
|
||||
ret ptr %c
|
||||
}
|
||||
|
||||
define ptr @load_bitcast_2(ptr %a) {
|
||||
; CHECK-LABEL: @load_bitcast_2(
|
||||
; CHECK-NEXT: [[C1:%.*]] = load ptr, ptr [[A:%.*]], align 8
|
||||
; CHECK-NEXT: ret ptr [[C1]]
|
||||
;
|
||||
%b = bitcast ptr %a to i8**
|
||||
%c = load i8*, i8** %b
|
||||
%d = bitcast i8* %c to ptr
|
||||
ret ptr %d
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user