diff options
| author | Olivier De Cannière <olivier.decanniere@qt.io> | 2023-08-28 11:06:01 +0200 |
|---|---|---|
| committer | Olivier De Cannière <olivier.decanniere@qt.io> | 2023-08-29 09:23:16 +0200 |
| commit | f5ba782da543fe1975c56dbaef90580e9fed4383 (patch) | |
| tree | bdb0561ef78ee9eccf547eb2e37684c8623f6d56 /src/qml/compiler/qv4codegen.cpp | |
| parent | b3f496ad0e2965fa64bdec4256d107a1bf03d73b (diff) | |
qv4codegen: Remove redundant jump instruction for coalesce expressions
For binary expressions with the ?? operator, two cases must be handled
in two code paths. When the lhs is defined, it is used as the result of
the expression. When the lhs is undefined, the rhs expression is used as
a fallback instead. Distinguishing between these two branches can be
done with a test such as CmpEqNull and a conditional jump based on it..
Previously, on top of a conditional JumpTrue to jump to the correct
location based on the test, a second JumpFalse was emitted to perform
the same operation a second time. This is redundant.
The second jump was removed and the logic was slightly reorganized.
Change-Id: I65479752d9fac8c18ef2475b062dd2b5262c372e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
| -rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 2df5a02998..888d9beaf0 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -1397,26 +1397,20 @@ bool Codegen::visit(BinaryExpression *ast) return false; BytecodeGenerator::Label iftrue = bytecodeGenerator->newLabel(); - BytecodeGenerator::Label iffalse = bytecodeGenerator->newLabel(); - Instruction::CmpNeNull cmp; + Instruction::CmpEqNull cmp; left = left.storeOnStack(); left.loadInAccumulator(); bytecodeGenerator->addInstruction(cmp); bytecodeGenerator->jumpTrue().link(iftrue); - bytecodeGenerator->jumpFalse().link(iffalse); blockTailCalls.unblock(); - iftrue.link(); - left.loadInAccumulator(); - BytecodeGenerator::Jump jump_endif = bytecodeGenerator->jump(); - - iffalse.link(); + iftrue.link(); Reference right = expression(ast->right); right.loadInAccumulator(); |
