Skip to content

Commit

Permalink
[ConstantFold] Get the correct vector type when folding a getelementptr.
Browse files Browse the repository at this point in the history
Differential Revision:  https://reviews.llvm.org/D26014

llvm-svn: 285371
  • Loading branch information
dcci committed Oct 28, 2016
1 parent 42b98e2 commit 3066514
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 2 additions & 6 deletions llvm/lib/IR/ConstantFold.cpp
Expand Up @@ -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);
}

Expand Down
15 changes: 15 additions & 0 deletions 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
}

0 comments on commit 3066514

Please sign in to comment.