diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index a6fbf42fa24..ee5ee0ee42c 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -726,11 +726,17 @@ Constant *llvm::ConstantFoldSelectInstruction(const Constant *Cond, Constant *llvm::ConstantFoldExtractElementInstruction(const Constant *Val, const Constant *Idx) { + if (isa(Val)) // ee(undef, x) -> undef + return UndefValue::get(cast(Val->getType())->getElementType()); + if (const ConstantPacked *CVal = dyn_cast(Val)) { if (const ConstantUInt *CIdx = dyn_cast(Idx)) { return const_cast(CVal->getOperand(CIdx->getValue())); + } else if (isa(Idx)) { + // ee({w,x,y,z}, undef) -> w (an arbitrary value). + return const_cast(CVal->getOperand(0)); } - } + } return 0; }