[llvm-commits] [llvm] r53950 - /llvm/trunk/include/llvm/Support/IRBuilder.h

Chris Lattner sabre at nondot.org
Tue Jul 22 23:58:10 PDT 2008


Author: lattner
Date: Wed Jul 23 01:58:10 2008
New Revision: 53950

URL: http://llvm.org/viewvc/llvm-project?rev=53950&view=rev
Log:
Make CreateBinOp/CreateNeg/CreateNot do constant folding.

Modified:
    llvm/trunk/include/llvm/Support/IRBuilder.h

Modified: llvm/trunk/include/llvm/Support/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=53950&r1=53949&r2=53950&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/IRBuilder.h Wed Jul 23 01:58:10 2008
@@ -243,15 +243,22 @@
     return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
   }
 
-  BinaryOperator *CreateBinOp(Instruction::BinaryOps Opc,
-                              Value *LHS, Value *RHS, const char *Name = "") {
+  Value *CreateBinOp(Instruction::BinaryOps Opc,
+                     Value *LHS, Value *RHS, const char *Name = "") {
+    if (Constant *LC = dyn_cast<Constant>(LHS))
+      if (Constant *RC = dyn_cast<Constant>(RHS))
+        return ConstantExpr::get(Opc, LC, RC);
     return Insert(BinaryOperator::Create(Opc, LHS, RHS), Name);
   }
   
-  BinaryOperator *CreateNeg(Value *V, const char *Name = "") {
+  Value *CreateNeg(Value *V, const char *Name = "") {
+    if (Constant *VC = dyn_cast<Constant>(V))
+      return ConstantExpr::getNeg(VC);
     return Insert(BinaryOperator::CreateNeg(V), Name);
   }
-  BinaryOperator *CreateNot(Value *V, const char *Name = "") {
+  Value *CreateNot(Value *V, const char *Name = "") {
+    if (Constant *VC = dyn_cast<Constant>(V))
+      return ConstantExpr::getNot(VC);
     return Insert(BinaryOperator::CreateNot(V), Name);
   }
   





More information about the llvm-commits mailing list