mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Optimization for exponentiation when the base is a literal
This commit is contained in:
committed by
hrkrshnn
parent
7a86a61b08
commit
418aa01c5b
@@ -695,17 +695,34 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)
|
||||
solAssert(false, "Unknown comparison operator.");
|
||||
define(_binOp) << expr << "\n";
|
||||
}
|
||||
else if (TokenTraits::isShiftOp(op) || op == Token::Exp)
|
||||
else if (op == Token::Exp)
|
||||
{
|
||||
IRVariable left = convert(_binOp.leftExpression(), *commonType);
|
||||
IRVariable right = convert(_binOp.rightExpression(), *type(_binOp.rightExpression()).mobileType());
|
||||
if (op == Token::Exp)
|
||||
|
||||
if (auto rationalNumberType = dynamic_cast<RationalNumberType const*>(_binOp.leftExpression().annotation().type))
|
||||
{
|
||||
solAssert(rationalNumberType->integerType(), "Invalid literal as the base for exponentiation.");
|
||||
solAssert(dynamic_cast<IntegerType const*>(commonType), "");
|
||||
|
||||
define(_binOp) << m_utils.overflowCheckedIntLiteralExpFunction(
|
||||
*rationalNumberType,
|
||||
dynamic_cast<IntegerType const&>(right.type()),
|
||||
dynamic_cast<IntegerType const&>(*commonType)
|
||||
) << "(" << right.name() << ")\n";
|
||||
}
|
||||
else
|
||||
define(_binOp) << m_utils.overflowCheckedIntExpFunction(
|
||||
dynamic_cast<IntegerType const&>(left.type()),
|
||||
dynamic_cast<IntegerType const&>(right.type())
|
||||
) << "(" << left.name() << ", " << right.name() << ")\n";
|
||||
else
|
||||
define(_binOp) << shiftOperation(_binOp.getOperator(), left, right) << "\n";
|
||||
|
||||
}
|
||||
else if (TokenTraits::isShiftOp(op))
|
||||
{
|
||||
IRVariable left = convert(_binOp.leftExpression(), *commonType);
|
||||
IRVariable right = convert(_binOp.rightExpression(), *type(_binOp.rightExpression()).mobileType());
|
||||
define(_binOp) << shiftOperation(_binOp.getOperator(), left, right) << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user