diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -667,13 +667,16 @@ } } + if (Constant *C = Val->getAggregateElement(CIdx)) + return C; + // Lane < Splat minimum vector width => extractelt Splat(x), Lane -> x if (CIdx->getValue().ult(ValVTy->getElementCount().getKnownMinValue())) { if (Constant *SplatVal = Val->getSplatValue()) return SplatVal; } - return Val->getAggregateElement(CIdx); + return nullptr; } Constant *llvm::ConstantFoldInsertElementInstruction(Constant *Val,