From 6fa4cdf92eb240f06c7705a8d72b408668b5869b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 31 Mar 2006 18:31:40 +0000 Subject: [PATCH] constant fold extractelement with undef operands. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27301 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/ConstantFold.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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; } -- 2.34.1