diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2018-05-07 15:08:12 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2018-05-25 09:46:39 +0000 |
commit | f783aa97c3d8d9df74212b4350203182d2d167f1 (patch) | |
tree | ea9ec96e80e2028542678a8db89e49acd713c7d1 /src/qml/compiler/qv4bytecodegenerator.cpp | |
parent | 8390b610401f42d239eee3390052cf685f47335d (diff) | |
download | qtdeclarative-f783aa97c3d8d9df74212b4350203182d2d167f1.tar.gz |
V4: Peephole optimize LoadReg/MoveReg
The following sequence:
StoreReg rX
LoadReg rX
Can be optimized by dropping the LoadReg, as the value is still in the
accumulator. Also, the sequence:
StoreReg rX
MoveReg rY, rX
Can be optimized to:
StoreReg rX
StoreReg rY
This last optimization prevents one load from the JS stack (reading rX).
Both cases are only valid if there is no label on the second
instruction.
Change-Id: Ibd4543459e1eab4da55e92248eba544c707c5456
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4bytecodegenerator.cpp')
-rw-r--r-- | src/qml/compiler/qv4bytecodegenerator.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4bytecodegenerator.cpp b/src/qml/compiler/qv4bytecodegenerator.cpp index 4d50654d27..1d1e98ea58 100644 --- a/src/qml/compiler/qv4bytecodegenerator.cpp +++ b/src/qml/compiler/qv4bytecodegenerator.cpp @@ -185,6 +185,25 @@ void BytecodeGenerator::finalize(Compiler::Context *context) } int BytecodeGenerator::addInstructionHelper(Instr::Type type, const Instr &i, int offsetOfOffset) { + if (lastInstrType == int(Instr::Type::StoreReg)) { + if (type == Instr::Type::LoadReg) { + if (i.LoadReg.reg == lastInstr.StoreReg.reg) { + // value is already in the accumulator + return -1; + } + } + if (type == Instr::Type::MoveReg) { + if (i.MoveReg.srcReg == lastInstr.StoreReg.reg) { + Instruction::StoreReg store; + store.reg = i.MoveReg.destReg; + addInstruction(store); + return -1; + } + } + } + lastInstrType = int(type); + lastInstr = i; + #if QT_CONFIG(qml_debug) if (debugMode && type != Instr::Type::Debug) { QT_WARNING_PUSH |