[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 18:02:54 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL285371: [ConstantFold] Get the correct vector type when folding a getelementptr. (authored by davide).

Changed prior to commit:
  https://reviews.llvm.org/D26014?vs=76101&id=76149#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26014

Files:
  llvm/trunk/lib/IR/ConstantFold.cpp
  llvm/trunk/test/Transforms/InstCombine/gep-vector.ll


Index: llvm/trunk/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp
+++ llvm/trunk/lib/IR/ConstantFold.cpp
@@ -2056,12 +2056,8 @@
     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);
   }
 
Index: llvm/trunk/test/Transforms/InstCombine/gep-vector.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/gep-vector.ll
+++ llvm/trunk/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
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26014.76149.patch
Type: text/x-patch
Size: 1482 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161028/3f1be44e/attachment.bin>


More information about the llvm-commits mailing list