diff options
author | Chris Lattner <sabre@nondot.org> | 2003-04-17 19:24:48 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-04-17 19:24:48 +0000 |
commit | d628f6a9a47dcb157db01a0568772fed1efcfe90 (patch) | |
tree | 7bbb6772fd7f2593366744c7993ad05494a72ba8 /lib/VMCore/Constants.cpp | |
parent | 27287de06b0a6d3c2713fc3a78281df8f5d1a0fa (diff) |
Don't build constantexprs that could be folded
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5801 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Constants.cpp')
-rw-r--r-- | lib/VMCore/Constants.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 27c48c8774..c519da36a8 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -5,6 +5,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Constants.h" +#include "llvm/ConstantHandling.h" #include "llvm/DerivedTypes.h" #include "llvm/iMemory.h" #include "llvm/SymbolTable.h" @@ -636,6 +637,9 @@ typedef pair<unsigned, vector<Constant*> > ExprMapKeyType; static ValueMap<const ExprMapKeyType, ConstantExpr> ExprConstants; Constant *ConstantExpr::getCast(Constant *C, const Type *Ty) { + if (Constant *FC = ConstantFoldCastInstruction(C, Ty)) + return FC; // Fold a few common cases... + // Look up the constant in the table first to ensure uniqueness vector<Constant*> argVec(1, C); const ExprMapKeyType &Key = make_pair(Instruction::Cast, argVec); @@ -649,6 +653,10 @@ Constant *ConstantExpr::getCast(Constant *C, const Type *Ty) { } Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) { + + if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2)) + return FC; // Fold a few common cases... + // Look up the constant in the table first to ensure uniqueness vector<Constant*> argVec(1, C1); argVec.push_back(C2); const ExprMapKeyType &Key = make_pair(Opcode, argVec); @@ -671,6 +679,8 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) { Constant *ConstantExpr::getGetElementPtr(Constant *C, const std::vector<Constant*> &IdxList){ + if (Constant *FC = ConstantFoldGetElementPtr(C, IdxList)) + return FC; // Fold a few common cases... const Type *Ty = C->getType(); // Look up the constant in the table first to ensure uniqueness |