diff options
Diffstat (limited to 'lib/Expr/ExprBuilder.cpp')
-rw-r--r-- | lib/Expr/ExprBuilder.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/Expr/ExprBuilder.cpp b/lib/Expr/ExprBuilder.cpp index 098da6ea..bb6f28ec 100644 --- a/lib/Expr/ExprBuilder.cpp +++ b/lib/Expr/ExprBuilder.cpp @@ -829,7 +829,7 @@ namespace { // X - (C + Y) ==> -C + (X - Y) if (ConstantExpr *CE = dyn_cast<ConstantExpr>(BE->left)) return Builder->Add(CE->Neg(), Builder->Sub(LHS, BE->right)); - // X - (Y + C) ==> -C + (X + Y); + // X - (Y + C) ==> -C + (X + Y) if (ConstantExpr *CE = dyn_cast<ConstantExpr>(BE->right)) return Builder->Add(CE->Neg(), Builder->Sub(LHS, BE->left)); break; @@ -849,6 +849,27 @@ namespace { return Base->Sub(LHS, RHS); } + + ref<Expr> Mul(const ref<ConstantExpr> &LHS, + const ref<NonConstantExpr> &RHS) { + if (LHS->isZero()) + return LHS; + if (LHS->isOne()) + return RHS; + // FIXME: Unbalance muls, fold constants through {sub,add}-with-constant, + // etc. + return Base->Mul(LHS, RHS); + } + + ref<Expr> Mul(const ref<NonConstantExpr> &LHS, + const ref<ConstantExpr> &RHS) { + return Mul(RHS, LHS); + } + + ref<Expr> Mul(const ref<NonConstantExpr> &LHS, + const ref<NonConstantExpr> &RHS) { + return Base->Mul(LHS, RHS); + } }; typedef ConstantSpecializedExprBuilder<ConstantFoldingBuilder> |