[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
Wed Oct 26 17:51:23 PDT 2016


davide updated this revision to Diff 75972.

https://reviews.llvm.org/D26014

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


Index: test/Transforms/InstCombine/gep-vector.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: lib/IR/ConstantFold.cpp
===================================================================
--- lib/IR/ConstantFold.cpp
+++ lib/IR/ConstantFold.cpp
@@ -2062,6 +2062,14 @@
     Type *GEPTy = PointerType::get(Ty, PtrTy->getAddressSpace());
     if (VectorType *VT = dyn_cast<VectorType>(C->getType()))
       GEPTy = VectorType::get(GEPTy, VT->getNumElements());
+    // When the getelementptr has one or more vector indices, it will
+    // return a vector of pointers.
+    else
+      for (auto &El : Idxs)
+        if (VectorType *VT = dyn_cast<VectorType>(El->getType())) {
+          GEPTy = VectorType::get(GEPTy, VT->getNumElements());
+          break;
+        }
     return UndefValue::get(GEPTy);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26014.75972.patch
Type: text/x-patch
Size: 1332 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161027/22cc351b/attachment.bin>


More information about the llvm-commits mailing list