From 5adb60b974ff40d7a298b9de558e9feb6adf030f Mon Sep 17 00:00:00 2001 From: "Hoang M. Le" Date: Tue, 31 May 2016 15:52:35 +0200 Subject: handle special cases of sdiv 1 and -1 --- lib/Solver/MetaSMTBuilder.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Solver/MetaSMTBuilder.h b/lib/Solver/MetaSMTBuilder.h index 9aca9f83..ebbfa814 100644 --- a/lib/Solver/MetaSMTBuilder.h +++ b/lib/Solver/MetaSMTBuilder.h @@ -843,12 +843,18 @@ typename SolverContext::result_type MetaSMTBuilder::constructActu typename SolverContext::result_type left_expr = construct(de->left, width_out); assert(*width_out != 1 && "uncanonicalized sdiv"); + bool optimized = false; ConstantExpr *CE = dyn_cast(de->right); if (CE && _optimizeDivides && (*width_out == 32)) { - res = constructSDivByConstant(left_expr, *width_out, CE->getZExtValue(32)); + llvm::APInt divisor = CE->getAPValue(); + if (divisor != llvm::APInt(CE->getWidth(), 1, false /*unsigned*/) && + divisor != llvm::APInt(CE->getWidth(), -1, true /*signed*/)) { + res = constructSDivByConstant(left_expr, *width_out, CE->getZExtValue(32)); + optimized = true; + } } - else { - res = evaluate(_solver, bvsdiv(left_expr, construct(de->right, width_out))); + if (!optimized) { + res = evaluate(_solver, bvsdiv(left_expr, construct(de->right, width_out))); } break; } -- cgit 1.4.1