[PATCH] D26014: [ConstantFold] Get the correct vector type when folding a getelementptr instruction with vector indices

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 26 23:06:04 PDT 2016


majnemer added inline comments.


================
Comment at: lib/IR/ConstantFold.cpp:2063-2070
     if (VectorType *VT = dyn_cast<VectorType>(C->getType()))
       GEPTy = VectorType::get(GEPTy, VT->getNumElements());
+    // When the getelementptr has one of more vector indices, it will
+    // return a vector of pointers. We guarantee that all the vectors
+    // in this case will have the same width, so we can just look at
+    // the first one.
+    else if (VectorType *VT = dyn_cast<VectorType>(Idxs[0]->getType()))
----------------
davide wrote:
> majnemer wrote:
> > Could this be replaced with `GetElementPtrInst::getGEPReturnType` ?
> hmm, I don't see an overload of `getGEPReturnType` which takes an `ArrayRef` of `Constant` but only `Value` -- do you want me to add one?
I think we can construct an `ArrayRef<Value *>` from an `ArrayRef<Constant *>` without violating any safety rules, something like `GetElementPtrInst::getGEPReturnType(PtrTy, {Idxs.begin(), Idxs.end()})` or `GetElementPtrInst::getGEPReturnType(PtrTy, {Idxs.data(), Idxs.size()})`


https://reviews.llvm.org/D26014





More information about the llvm-commits mailing list