[llvm] r285371 - [ConstantFold] Get the correct vector type when folding a getelementptr.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 27 17:53:17 PDT 2016
Author: davide
Date: Thu Oct 27 19:53:16 2016
New Revision: 285371
URL: http://llvm.org/viewvc/llvm-project?rev=285371&view=rev
Log:
[ConstantFold] Get the correct vector type when folding a getelementptr.
Differential Revision: https://reviews.llvm.org/D26014
Added:
llvm/trunk/test/Transforms/InstCombine/gep-vector.ll
Modified:
llvm/trunk/lib/IR/ConstantFold.cpp
Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=285371&r1=285370&r2=285371&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Thu Oct 27 19:53:16 2016
@@ -2056,12 +2056,8 @@ static Constant *ConstantFoldGetElementP
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);
}
Added: llvm/trunk/test/Transforms/InstCombine/gep-vector.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/gep-vector.ll?rev=285371&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/gep-vector.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/gep-vector.ll Thu Oct 27 19:53:16 2016
@@ -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
+}
More information about the llvm-commits
mailing list