constant fold extractelement with undef operands.
authorChris Lattner <sabre@nondot.org>
Fri, 31 Mar 2006 18:31:40 +0000 (18:31 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 31 Mar 2006 18:31:40 +0000 (18:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27301 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/ConstantFold.cpp

index a6fbf42fa24a4aa59784f0c9a9fe1a11767a2075..ee5ee0ee42c2b59203d62d7f11d0664de3524a3d 100644 (file)
@@ -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;
 }