diff options
| author | Davide Italiano <davide@freebsd.org> | 2016-10-28 00:53:16 +0000 |
|---|---|---|
| committer | Davide Italiano <davide@freebsd.org> | 2016-10-28 00:53:16 +0000 |
| commit | 30665147f92a237094502ad9e8e59914cdbecfc1 (patch) | |
| tree | 7f9ba87e9352a2cb53a2f146bccf34d104388ed5 | |
| parent | 42b98e2a824a234c69b46fe26b87906a5eb198d5 (diff) | |
| download | bcm5719-llvm-30665147f92a237094502ad9e8e59914cdbecfc1.tar.gz bcm5719-llvm-30665147f92a237094502ad9e8e59914cdbecfc1.zip | |
[ConstantFold] Get the correct vector type when folding a getelementptr.
Differential Revision: https://reviews.llvm.org/D26014
llvm-svn: 285371
| -rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 8 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/gep-vector.ll | 15 |
2 files changed, 17 insertions, 6 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 7bbe9b74cdc..5bfcc274ae9 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -2056,12 +2056,8 @@ static Constant *ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C, return C; if (isa<UndefValue>(C)) { - PointerType *PtrTy = cast<PointerType>(C->getType()->getScalarType()); - 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()); + Type *GEPTy = GetElementPtrInst::getGEPReturnType(C, + makeArrayRef((Value * const *)Idxs.data(), Idxs.size())); return UndefValue::get(GEPTy); } diff --git a/llvm/test/Transforms/InstCombine/gep-vector.ll b/llvm/test/Transforms/InstCombine/gep-vector.ll new file mode 100644 index 00000000000..ce021bf207f --- /dev/null +++ b/llvm/test/Transforms/InstCombine/gep-vector.ll @@ -0,0 +1,15 @@ +; RUN: opt -instcombine %s -S | FileCheck %s + +; CHECK-LABEL: patatino +; CHECK-NEXT: ret <8 x i64*> undef +define <8 x i64*> @patatino() { + %el = getelementptr i64, <8 x i64*> undef, <8 x i64> undef + ret <8 x i64*> %el +} + +; CHECK-LABEL: patatino2 +; CHECK-NEXT: ret <8 x i64*> undef +define <8 x i64*> @patatino2() { + %el = getelementptr inbounds i64, i64* undef, <8 x i64> undef + ret <8 x i64*> %el +} |

