aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-03-31 18:31:40 +0000
committerChris Lattner <sabre@nondot.org>2006-03-31 18:31:40 +0000
commit6fa4cdf92eb240f06c7705a8d72b408668b5869b (patch)
tree0a535c08c6ebbc4657638a967a9bd7ff9bb47e5b
parent1f13c88939e2d243c9802f7da83ae8daccb285eb (diff)
downloadexternal_llvm-6fa4cdf92eb240f06c7705a8d72b408668b5869b.zip
external_llvm-6fa4cdf92eb240f06c7705a8d72b408668b5869b.tar.gz
external_llvm-6fa4cdf92eb240f06c7705a8d72b408668b5869b.tar.bz2
constant fold extractelement with undef operands.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27301 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/VMCore/ConstantFold.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index a6fbf42..ee5ee0e 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<UndefValue>(Val)) // ee(undef, x) -> undef
+ return UndefValue::get(cast<PackedType>(Val->getType())->getElementType());
+
if (const ConstantPacked *CVal = dyn_cast<ConstantPacked>(Val)) {
if (const ConstantUInt *CIdx = dyn_cast<ConstantUInt>(Idx)) {
return const_cast<Constant*>(CVal->getOperand(CIdx->getValue()));
+ } else if (isa<UndefValue>(Idx)) {
+ // ee({w,x,y,z}, undef) -> w (an arbitrary value).
+ return const_cast<Constant*>(CVal->getOperand(0));
}
- }
+ }
return 0;
}