From: Chris Lattner Date: Fri, 31 Mar 2006 18:31:40 +0000 (+0000) Subject: constant fold extractelement with undef operands. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6fa4cdf92eb240f06c7705a8d72b408668b5869b;p=oota-llvm.git constant fold extractelement with undef operands. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27301 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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; }