[PATCH] D104718: [OpaquePtr] Support changing load type in InstCombine
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 22 12:16:29 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7bb7fa12e73b: [OpaquePtr] Support changing load type in InstCombine (authored by nikic).
Changed prior to commit:
https://reviews.llvm.org/D104718?vs=353659&id=353747#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104718/new/
https://reviews.llvm.org/D104718
Files:
llvm/include/llvm/IR/Type.h
llvm/lib/IR/Type.cpp
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/test/Transforms/InstCombine/opaque-ptr.ll
Index: llvm/test/Transforms/InstCombine/opaque-ptr.ll
===================================================================
--- llvm/test/Transforms/InstCombine/opaque-ptr.ll
+++ llvm/test/Transforms/InstCombine/opaque-ptr.ll
@@ -87,3 +87,24 @@
;
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
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -463,11 +463,11 @@
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);
Index: llvm/lib/IR/Type.cpp
===================================================================
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -725,8 +725,13 @@
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) {
Index: llvm/include/llvm/IR/Type.h
===================================================================
--- llvm/include/llvm/IR/Type.h
+++ llvm/include/llvm/IR/Type.h
@@ -483,6 +483,7 @@
/// 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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104718.353747.patch
Type: text/x-patch
Size: 2885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210622/ae061a57/attachment.bin>
More information about the llvm-commits
mailing list