From cc1be11d6c36d1da99af09181bb756b83c9dc54e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 19 Mar 2015 12:07:10 +0100 Subject: [PATCH] Constant folding in div-based operators disabled There is a bug in LLVM arbitrary precision division algorithm. --- evmjit/libevmjit/Arith256.cpp | 46 ++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/evmjit/libevmjit/Arith256.cpp b/evmjit/libevmjit/Arith256.cpp index f24626750..e88fda432 100644 --- a/evmjit/libevmjit/Arith256.cpp +++ b/evmjit/libevmjit/Arith256.cpp @@ -371,17 +371,18 @@ llvm::Value* Arith256::mul(llvm::Value* _arg1, llvm::Value* _arg2) std::pair Arith256::div(llvm::Value* _arg1, llvm::Value* _arg2) { - if (auto c1 = llvm::dyn_cast(_arg1)) - { - if (auto c2 = llvm::dyn_cast(_arg2)) - { - if (!c2->getValue()) - return std::make_pair(Constant::get(0), Constant::get(0)); - auto div = Constant::get(c1->getValue().udiv(c2->getValue())); - auto mod = Constant::get(c1->getValue().urem(c2->getValue())); - return std::make_pair(div, mod); - } - } + // FIXME: Disabled because of llvm::APInt::urem bug +// if (auto c1 = llvm::dyn_cast(_arg1)) +// { +// if (auto c2 = llvm::dyn_cast(_arg2)) +// { +// if (!c2->getValue()) +// return std::make_pair(Constant::get(0), Constant::get(0)); +// auto div = Constant::get(c1->getValue().udiv(c2->getValue())); +// auto mod = Constant::get(c1->getValue().urem(c2->getValue())); +// return std::make_pair(div, mod); +// } +// } auto r = createCall(getDivFunc(Type::Word), {_arg1, _arg2}); auto div = m_builder.CreateExtractValue(r, 0, "div"); @@ -391,17 +392,18 @@ std::pair Arith256::div(llvm::Value* _arg1, llvm::Va std::pair Arith256::sdiv(llvm::Value* _x, llvm::Value* _y) { - if (auto c1 = llvm::dyn_cast(_x)) - { - if (auto c2 = llvm::dyn_cast(_y)) - { - if (!c2->getValue()) - return std::make_pair(Constant::get(0), Constant::get(0)); - auto div = Constant::get(c1->getValue().sdiv(c2->getValue())); - auto mod = Constant::get(c1->getValue().srem(c2->getValue())); - return std::make_pair(div, mod); - } - } + // FIXME: Disabled because of llvm::APInt::urem bug +// if (auto c1 = llvm::dyn_cast(_x)) +// { +// if (auto c2 = llvm::dyn_cast(_y)) +// { +// if (!c2->getValue()) +// return std::make_pair(Constant::get(0), Constant::get(0)); +// auto div = Constant::get(c1->getValue().sdiv(c2->getValue())); +// auto mod = Constant::get(c1->getValue().srem(c2->getValue())); +// return std::make_pair(div, mod); +// } +// } auto xIsNeg = m_builder.CreateICmpSLT(_x, Constant::get(0)); auto xNeg = m_builder.CreateSub(Constant::get(0), _x);