[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp ConstantFolding.h Constants.cpp
Robert L. Bocchino Jr.
bocchino at persephone.cs.uiuc.edu
Tue Jan 10 12:04:16 PST 2006
Changes in directory llvm/lib/VMCore:
ConstantFolding.cpp updated: 1.81 -> 1.82
ConstantFolding.h updated: 1.45 -> 1.46
Constants.cpp updated: 1.143 -> 1.144
---
Log message:
Added constant folding support for the extractelement operation.
---
Diffs of the changes: (+14 -0)
ConstantFolding.cpp | 10 ++++++++++
ConstantFolding.h | 2 ++
Constants.cpp | 2 ++
3 files changed, 14 insertions(+)
Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.81 llvm/lib/VMCore/ConstantFolding.cpp:1.82
--- llvm/lib/VMCore/ConstantFolding.cpp:1.81 Thu Jan 5 01:49:30 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Tue Jan 10 14:03:46 2006
@@ -724,6 +724,16 @@
return 0;
}
+Constant *llvm::ConstantFoldExtractElementInstruction(const Constant *Val,
+ const Constant *Idx) {
+ if (const ConstantPacked *CVal = dyn_cast<ConstantPacked>(Val)) {
+ if (const ConstantUInt *CIdx = dyn_cast<ConstantUInt>(Idx)) {
+ return const_cast<Constant*>(CVal->getOperand(CIdx->getValue()));
+ }
+ }
+ return 0;
+}
+
/// isZeroSizedType - This type is zero sized if its an array or structure of
/// zero sized types. The only leaf zero sized type is an empty structure.
static bool isMaybeZeroSizedType(const Type *Ty) {
Index: llvm/lib/VMCore/ConstantFolding.h
diff -u llvm/lib/VMCore/ConstantFolding.h:1.45 llvm/lib/VMCore/ConstantFolding.h:1.46
--- llvm/lib/VMCore/ConstantFolding.h:1.45 Thu Apr 21 18:46:51 2005
+++ llvm/lib/VMCore/ConstantFolding.h Tue Jan 10 14:03:46 2006
@@ -31,6 +31,8 @@
Constant *ConstantFoldSelectInstruction(const Constant *Cond,
const Constant *V1,
const Constant *V2);
+ Constant *ConstantFoldExtractElementInstruction(const Constant *Val,
+ const Constant *Idx);
Constant *ConstantFoldBinaryInstruction(unsigned Opcode, const Constant *V1,
const Constant *V2);
Constant *ConstantFoldGetElementPtr(const Constant *C,
Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.143 llvm/lib/VMCore/Constants.cpp:1.144
--- llvm/lib/VMCore/Constants.cpp:1.143 Tue Jan 10 13:05:24 2006
+++ llvm/lib/VMCore/Constants.cpp Tue Jan 10 14:03:46 2006
@@ -1403,6 +1403,8 @@
Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val,
Constant *Idx) {
+ if (Constant *FC = ConstantFoldExtractElementInstruction(Val, Idx))
+ return FC; // Fold a few common cases...
// Look up the constant in the table first to ensure uniqueness
std::vector<Constant*> ArgVec(1, Val);
ArgVec.push_back(Idx);
More information about the llvm-commits
mailing list