Return undef value (instead of arbitrary) for wrong or undef index in

ConstantVector.

llvm-svn: 139007
This commit is contained in:
Jakub Staszak 2011-09-02 17:01:40 +00:00
parent 132e24bf28
commit 4df162e09b

View File

@ -763,12 +763,12 @@ Constant *llvm::ConstantFoldExtractElementInstruction(Constant *Val,
if (ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx)) {
uint64_t Index = CIdx->getZExtValue();
if (Index >= CVal->getNumOperands())
// ee({w,x,y,z}, wrong_value) -> w (an arbitrary value).
return CVal->getOperand(0);
// ee({w,x,y,z}, wrong_value) -> undef
return UndefValue::get(cast<VectorType>(Val->getType())->getElementType());
return CVal->getOperand(CIdx->getZExtValue());
} else if (isa<UndefValue>(Idx)) {
// ee({w,x,y,z}, undef) -> w (an arbitrary value).
return CVal->getOperand(0);
// ee({w,x,y,z}, undef) -> undef
return UndefValue::get(cast<VectorType>(Val->getType())->getElementType());
}
}
return 0;