[PATCH] D37928: [ConstantFold] Return the correct type when folding a GEP with vector indices
Davide Italiano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 15 13:54:44 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL313394: [ConstantFold] Return the correct type when folding a GEP with vector indices. (authored by davide).
Changed prior to commit:
https://reviews.llvm.org/D37928?vs=115478&id=115483#toc
Repository:
rL LLVM
https://reviews.llvm.org/D37928
Files:
llvm/trunk/lib/IR/ConstantFold.cpp
llvm/trunk/test/Transforms/InstCombine/pr34627.ll
Index: llvm/trunk/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp
+++ llvm/trunk/lib/IR/ConstantFold.cpp
@@ -2062,9 +2062,20 @@
Type *Ty = GetElementPtrInst::getIndexedType(PointeeTy, Idxs);
assert(Ty && "Invalid indices for GEP!");
+ Type *OrigGEPTy = PointerType::get(Ty, PtrTy->getAddressSpace());
Type *GEPTy = PointerType::get(Ty, PtrTy->getAddressSpace());
if (VectorType *VT = dyn_cast<VectorType>(C->getType()))
- GEPTy = VectorType::get(GEPTy, VT->getNumElements());
+ GEPTy = VectorType::get(OrigGEPTy, VT->getNumElements());
+
+ // The GEP returns a vector of pointers when one of more of
+ // its arguments is a vector.
+ for (unsigned i = 0, e = Idxs.size(); i != e; ++i) {
+ if (auto *VT = dyn_cast<VectorType>(Idxs[i]->getType())) {
+ GEPTy = VectorType::get(OrigGEPTy, VT->getNumElements());
+ break;
+ }
+ }
+
return Constant::getNullValue(GEPTy);
}
}
Index: llvm/trunk/test/Transforms/InstCombine/pr34627.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/pr34627.ll
+++ llvm/trunk/test/Transforms/InstCombine/pr34627.ll
@@ -0,0 +1,11 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -instcombine %s |FileCheck %s
+
+define <2 x i16> @patatino() {
+; CHECK-LABEL: @patatino(
+; CHECK-NEXT: ret <2 x i16> zeroinitializer
+;
+ %tmp2 = getelementptr inbounds [1 x i16], [1 x i16]* null, i16 0, <2 x i16> undef
+ %tmp3 = ptrtoint <2 x i16*> %tmp2 to <2 x i16>
+ ret <2 x i16> %tmp3
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37928.115483.patch
Type: text/x-patch
Size: 1711 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170915/ac494e0e/attachment.bin>
More information about the llvm-commits
mailing list