[PATCH] D26014: [ConstantFold] Get the correct vector type when folding a getelementptr instruction with vector indices
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 27 14:01:07 PDT 2016
davide updated this revision to Diff 76096.
davide added a comment.
Simplify.
https://reviews.llvm.org/D26014
Files:
include/llvm/IR/Instructions.h
lib/IR/ConstantFold.cpp
Index: lib/IR/ConstantFold.cpp
===================================================================
--- lib/IR/ConstantFold.cpp
+++ lib/IR/ConstantFold.cpp
@@ -2060,8 +2060,10 @@
Type *Ty = GetElementPtrInst::getIndexedType(PointeeTy, Idxs);
assert(Ty && "Invalid indices for GEP!");
Type *GEPTy = PointerType::get(Ty, PtrTy->getAddressSpace());
- if (VectorType *VT = dyn_cast<VectorType>(C->getType()))
- GEPTy = VectorType::get(GEPTy, VT->getNumElements());
+ // When the getelementptr has one or more vector indices, it will
+ // return a vector of pointers.
+ GEPTy = GetElementPtrInst::getGEPReturnType(C,
+ makeArrayRef((Value * const *)Idxs.data(), Idxs.size()));
return UndefValue::get(GEPTy);
}
Index: include/llvm/IR/Instructions.h
===================================================================
--- include/llvm/IR/Instructions.h
+++ include/llvm/IR/Instructions.h
@@ -959,6 +959,11 @@
/// Returns the pointer type returned by the GEP
/// instruction, which may be a vector of pointers.
+ static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
+ return getGEPReturnType(
+ cast<PointerType>(Ptr->getType()->getScalarType())->getElementType(),
+ Ptr, IdxList);
+ }
static Type *getGEPReturnType(Type *ElTy, Value *Ptr,
ArrayRef<Value *> IdxList) {
Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26014.76096.patch
Type: text/x-patch
Size: 1467 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161027/b0550938/attachment.bin>
More information about the llvm-commits
mailing list