From 2a05f46ae3bc3a0fb9fc0df78bb8b55a09e6e9a3 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 16 Jun 2009 03:33:57 +0000 Subject: Add (very) basic constant folding for And,Or,Xor. - Lots more important goodness can be done here. git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@73461 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Expr/ExprBuilder.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) (limited to 'lib/Expr') diff --git a/lib/Expr/ExprBuilder.cpp b/lib/Expr/ExprBuilder.cpp index bb6f28ec..aaddb3e3 100644 --- a/lib/Expr/ExprBuilder.cpp +++ b/lib/Expr/ExprBuilder.cpp @@ -856,8 +856,8 @@ namespace { return LHS; if (LHS->isOne()) return RHS; - // FIXME: Unbalance muls, fold constants through {sub,add}-with-constant, - // etc. + // FIXME: Unbalance nested muls, fold constants through + // {sub,add}-with-constant, etc. return Base->Mul(LHS, RHS); } @@ -870,6 +870,67 @@ namespace { const ref &RHS) { return Base->Mul(LHS, RHS); } + + ref And(const ref &LHS, + const ref &RHS) { + if (LHS->isZero()) + return LHS; + if (LHS->isAllOnes()) + return RHS; + // FIXME: Unbalance nested ands, fold constants through + // {and,or}-with-constant, etc. + return Base->And(LHS, RHS); + } + + ref And(const ref &LHS, + const ref &RHS) { + return And(RHS, LHS); + } + + ref And(const ref &LHS, + const ref &RHS) { + return Base->And(LHS, RHS); + } + + ref Or(const ref &LHS, + const ref &RHS) { + if (LHS->isZero()) + return RHS; + if (LHS->isAllOnes()) + return LHS; + // FIXME: Unbalance nested ors, fold constants through + // {and,or}-with-constant, etc. + return Base->Or(LHS, RHS); + } + + ref Or(const ref &LHS, + const ref &RHS) { + return Or(RHS, LHS); + } + + ref Or(const ref &LHS, + const ref &RHS) { + return Base->Or(LHS, RHS); + } + + ref Xor(const ref &LHS, + const ref &RHS) { + if (LHS->isZero()) + return RHS; + // FIXME: Unbalance nested ors, fold constants through + // {and,or}-with-constant, etc. + return Base->Xor(LHS, RHS); + } + + ref Xor(const ref &LHS, + const ref &RHS) { + return Xor(RHS, LHS); + } + + ref Xor(const ref &LHS, + const ref &RHS) { + return Base->Xor(LHS, RHS); + } }; typedef ConstantSpecializedExprBuilder -- cgit 1.4.1