summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-07-23 06:58:10 +0000
committerChris Lattner <sabre@nondot.org>2008-07-23 06:58:10 +0000
commit6bbb53dac82cc7aeff863f31ca790bd15d8eee91 (patch)
treea0370196ad7fc61625cf7bbb040deffafabcd0ee /llvm
parent28ee5b3d299f0d0bf2990918fd29d93a6113704b (diff)
downloadbcm5719-llvm-6bbb53dac82cc7aeff863f31ca790bd15d8eee91.tar.gz
bcm5719-llvm-6bbb53dac82cc7aeff863f31ca790bd15d8eee91.zip
Make CreateBinOp/CreateNeg/CreateNot do constant folding.
llvm-svn: 53950
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Support/IRBuilder.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/include/llvm/Support/IRBuilder.h b/llvm/include/llvm/Support/IRBuilder.h
index b025d4c6578..9cc1d903f0f 100644
--- a/llvm/include/llvm/Support/IRBuilder.h
+++ b/llvm/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<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);
}
OpenPOWER on IntegriCloud