From fcf0e86bf2ea9ddf104bea9a0764f78623a11889 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 23 Jul 2008 06:58:10 +0000 Subject: Make CreateBinOp/CreateNeg/CreateNot do constant folding. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53950 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/IRBuilder.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'include/llvm/Support/IRBuilder.h') diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index b025d4c657..9cc1d903f0 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -243,15 +243,22 @@ public: 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(LHS)) + if (Constant *RC = dyn_cast(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(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(V)) + return ConstantExpr::getNot(VC); return Insert(BinaryOperator::CreateNot(V), Name); } -- cgit v1.2.3