[PATCH] D104652: [OpaquePtr] Return opaque pointer from opaque pointer GEP
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 21 09:38:20 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9f779195d311: [OpaquePtr] Return opaque pointer from opaque pointer GEP (authored by nikic).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104652/new/
https://reviews.llvm.org/D104652
Files:
llvm/include/llvm/IR/Instructions.h
llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
llvm/test/Assembler/opaque-ptr.ll
Index: llvm/test/Assembler/opaque-ptr.ll
===================================================================
--- llvm/test/Assembler/opaque-ptr.ll
+++ llvm/test/Assembler/opaque-ptr.ll
@@ -41,12 +41,28 @@
ret void
}
-; CHECK: define void @gep(ptr %a)
-; CHECK: %b = getelementptr i8, ptr %a, i32 2
-; CHECK: ret void
-define void @gep(ptr %a) {
- %b = getelementptr i8, ptr %a, i32 2
- ret void
+; CHECK: define ptr @gep(ptr %a)
+; CHECK: %res = getelementptr i8, ptr %a, i32 2
+; CHECK: ret ptr %res
+define ptr @gep(ptr %a) {
+ %res = getelementptr i8, ptr %a, i32 2
+ ret ptr %res
+}
+
+; CHECK: define <2 x ptr> @gep_vec1(ptr %a)
+; CHECK: %res = getelementptr i8, ptr %a, <2 x i32> <i32 1, i32 2>
+; CHECK: ret <2 x ptr> %res
+define <2 x ptr> @gep_vec1(ptr %a) {
+ %res = getelementptr i8, ptr %a, <2 x i32> <i32 1, i32 2>
+ ret <2 x ptr> %res
+}
+
+; CHECK: define <2 x ptr> @gep_vec2(<2 x ptr> %a)
+; CHECK: %res = getelementptr i8, <2 x ptr> %a, i32 2
+; CHECK: ret <2 x ptr> %res
+define <2 x ptr> @gep_vec2(<2 x ptr> %a) {
+ %res = getelementptr i8, <2 x ptr> %a, i32 2
+ ret <2 x ptr> %res
}
; CHECK: define void @cmpxchg(ptr %p, i32 %a, i32 %b)
Index: llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
===================================================================
--- llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -463,6 +463,8 @@
}
if (auto *SVI = dyn_cast<ShuffleVectorInst>(&I))
EnumerateType(SVI->getShuffleMaskForBitcode()->getType());
+ if (auto *GEP = dyn_cast<GetElementPtrInst>(&I))
+ EnumerateType(GEP->getSourceElementType());
EnumerateType(I.getType());
if (const auto *Call = dyn_cast<CallBase>(&I))
EnumerateAttributes(Call->getAttributes());
Index: llvm/include/llvm/IR/Instructions.h
===================================================================
--- llvm/include/llvm/IR/Instructions.h
+++ llvm/include/llvm/IR/Instructions.h
@@ -1098,8 +1098,12 @@
/// instruction, which may be a vector of pointers.
static Type *getGEPReturnType(Type *ElTy, Value *Ptr,
ArrayRef<Value *> IdxList) {
- Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)),
- Ptr->getType()->getPointerAddressSpace());
+ PointerType *OrigPtrTy = cast<PointerType>(Ptr->getType()->getScalarType());
+ unsigned AddrSpace = OrigPtrTy->getAddressSpace();
+ Type *ResultElemTy = checkGEPType(getIndexedType(ElTy, IdxList));
+ Type *PtrTy = OrigPtrTy->isOpaque()
+ ? PointerType::get(OrigPtrTy->getContext(), AddrSpace)
+ : PointerType::get(ResultElemTy, AddrSpace);
// Vector GEP
if (auto *PtrVTy = dyn_cast<VectorType>(Ptr->getType())) {
ElementCount EltCount = PtrVTy->getElementCount();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104652.353398.patch
Type: text/x-patch
Size: 2902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210621/6bae018d/attachment.bin>
More information about the llvm-commits
mailing list