diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-01-24 11:45:54 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-02-15 10:12:52 +0000 |
commit | 72ccc49e66ff2edebd758efa27facca034bff10d (patch) | |
tree | b30c7e533530f81ea3b688ac38769b6f5fc2538f /src | |
parent | b334375720f61b2b3c9f5040f55563b622699cba (diff) |
Remove unnecessary assignment of binop results to temporaries
In many cases, the result can be directly assigned to the left-hand
side. So leave it to the place where the binop is used to decide when
to assign it to a temporary.
Change-Id: I9a88a71a77aa73afe88007eca744d3782fca34ac
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 39 | ||||
-rw-r--r-- | src/qml/jit/qv4binop.cpp | 1 |
2 files changed, 22 insertions, 18 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 7d3ad38f97..8d0126ebb3 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -73,6 +73,25 @@ static inline void setLocation(IR::Stmt *s, const SourceLocation &loc) s->location = loc; } +static bool cjumpCanHandle(IR::AluOp op) +{ + switch (op) { + case IR::OpIn: + case IR::OpInstanceof: + case IR::OpEqual: + case IR::OpNotEqual: + case IR::OpGe: + case IR::OpGt: + case IR::OpLe: + case IR::OpLt: + case IR::OpStrictEqual: + case IR::OpStrictNotEqual: + return true; + default: + return false; + } +} + Codegen::ScanFunctions::ScanFunctions(Codegen *cg, const QString &sourceCode, CompilationMode defaultProgramMode) : _cg(cg) , _sourceCode(sourceCode) @@ -715,7 +734,7 @@ IR::Stmt *Codegen::cjump(IR::Expr *cond, IR::BasicBlock *iftrue, IR::BasicBlock if (hasError) return 0; - if (! (cond->asTemp() || cond->asBinop())) { + if (! (cond->asTemp() || (cond->asBinop() && cjumpCanHandle(cond->asBinop()->op)) )) { const unsigned t = _block->newTemp(); move(_block->TEMP(t), cond); cond = _block->TEMP(t); @@ -1281,14 +1300,7 @@ bool Codegen::visit(BinaryExpression *ast) if (_expr.accept(cx)) { setLocation(cjump(binop(IR::binaryOperator(ast->op), left, *right, ast->operatorToken), _expr.iftrue, _expr.iffalse), ast->operatorToken); } else { - IR::Expr *e = binop(IR::binaryOperator(ast->op), left, *right, ast->operatorToken); - if (e->asConst() || e->asString()) - _expr.code = e; - else { - const unsigned t = _block->newTemp(); - setLocation(move(_block->TEMP(t), e), ast->operatorToken); - _expr.code = _block->TEMP(t); - } + _expr.code = binop(IR::binaryOperator(ast->op), left, *right, ast->operatorToken); } break; } @@ -1314,14 +1326,7 @@ bool Codegen::visit(BinaryExpression *ast) if (hasError) return false; - IR::Expr *e = binop(IR::binaryOperator(ast->op), left, *right, ast->operatorToken); - if (e->asConst() || e->asString()) - _expr.code = e; - else { - const unsigned t = _block->newTemp(); - setLocation(move(_block->TEMP(t), e), ast->operatorToken); - _expr.code = _block->TEMP(t); - } + _expr.code = binop(IR::binaryOperator(ast->op), left, *right, ast->operatorToken); break; } diff --git a/src/qml/jit/qv4binop.cpp b/src/qml/jit/qv4binop.cpp index 6d20a4e042..22067bbb13 100644 --- a/src/qml/jit/qv4binop.cpp +++ b/src/qml/jit/qv4binop.cpp @@ -331,7 +331,6 @@ void Binop<JITAssembler>::doubleBinop(IR::Expr *lhs, IR::Expr *rhs, IR::Expr *ta break; default: { - Q_ASSERT(target->type == IR::BoolType); Jump trueCase = as->branchDouble(false, op, lhs, rhs); as->storeBool(false, target); Jump done = as->jump(); |