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

Chris Lattner lattner at cs.uiuc.edu
Thu Apr 17 14:25:03 PDT 2003


Changes in directory llvm/lib/VMCore:

Constants.cpp updated: 1.35 -> 1.36

---
Log message:

Don't build constantexprs that could be folded


---
Diffs of the changes:

Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.35 llvm/lib/VMCore/Constants.cpp:1.36
--- llvm/lib/VMCore/Constants.cpp:1.35	Wed Apr 16 17:40:51 2003
+++ llvm/lib/VMCore/Constants.cpp	Thu Apr 17 14:24:48 2003
@@ -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 @@
 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::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::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





More information about the llvm-commits mailing list