From 077d36ae021ca14b90042db269fb241024c20a5d Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Fri, 16 Mar 2018 17:50:44 +0000 Subject: Pull in r327638 from upstream llvm trunk (by Matthew Simpson): [ConstantFolding, InstSimplify] Handle more vector GEPs This patch addresses some additional cases where the compiler crashes upon encountering vector GEPs. This should fix PR36116. Differential Revision: https://reviews.llvm.org/D44219 Reference: https://bugs.llvm.org/show_bug.cgi?id=36116 This fixes an assertion when building the emulators/snes9x port. Reported by: jbeich PR: 225471 MFC after: 3 months X-MFC-With: r327952 --- contrib/llvm/lib/IR/ConstantFold.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'contrib/llvm/lib/IR/ConstantFold.cpp') diff --git a/contrib/llvm/lib/IR/ConstantFold.cpp b/contrib/llvm/lib/IR/ConstantFold.cpp index 59818a1425f1..adb6724fc9c0 100644 --- a/contrib/llvm/lib/IR/ConstantFold.cpp +++ b/contrib/llvm/lib/IR/ConstantFold.cpp @@ -2018,8 +2018,16 @@ static bool isInBoundsIndices(ArrayRef Idxs) { // If the first index is one and all the rest are zero, it's in bounds, // by the one-past-the-end rule. - if (!cast(Idxs[0])->isOne()) - return false; + if (auto *CI = dyn_cast(Idxs[0])) { + if (!CI->isOne()) + return false; + } else { + auto *CV = cast(Idxs[0]); + CI = dyn_cast_or_null(CV->getSplatValue()); + if (!CI || !CI->isOne()) + return false; + } + for (unsigned i = 1, e = Idxs.size(); i != e; ++i) if (!cast(Idxs[i])->isNullValue()) return false; @@ -2049,15 +2057,18 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C, ArrayRef Idxs) { if (Idxs.empty()) return C; - if (isa(C)) { - Type *GEPTy = GetElementPtrInst::getGEPReturnType( - C, makeArrayRef((Value * const *)Idxs.data(), Idxs.size())); + Type *GEPTy = GetElementPtrInst::getGEPReturnType( + C, makeArrayRef((Value *const *)Idxs.data(), Idxs.size())); + + if (isa(C)) return UndefValue::get(GEPTy); - } Constant *Idx0 = cast(Idxs[0]); if (Idxs.size() == 1 && (Idx0->isNullValue() || isa(Idx0))) - return C; + return GEPTy->isVectorTy() && !C->getType()->isVectorTy() + ? ConstantVector::getSplat( + cast(GEPTy)->getNumElements(), C) + : C; if (C->isNullValue()) { bool isNull = true; -- cgit v1.2.3