[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Mar 31 10:31:52 PST 2006



Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.83 -> 1.84
---
Log message:

constant fold extractelement with undef operands.


---
Diffs of the changes:  (+7 -1)

 ConstantFolding.cpp |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletion(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.83 llvm/lib/VMCore/ConstantFolding.cpp:1.84
--- llvm/lib/VMCore/ConstantFolding.cpp:1.83	Tue Jan 17 14:07:22 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp	Fri Mar 31 12:31:40 2006
@@ -726,11 +726,17 @@
 
 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;
 }
 






More information about the llvm-commits mailing list