aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2018-05-07 15:08:12 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2018-05-25 09:46:39 +0000
commitf783aa97c3d8d9df74212b4350203182d2d167f1 (patch)
treeea9ec96e80e2028542678a8db89e49acd713c7d1 /src/qml
parent8390b610401f42d239eee3390052cf685f47335d (diff)
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')
-rw-r--r--src/qml/compiler/qv4bytecodegenerator.cpp19
-rw-r--r--src/qml/compiler/qv4bytecodegenerator_p.h13
2 files changed, 31 insertions, 1 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
diff --git a/src/qml/compiler/qv4bytecodegenerator_p.h b/src/qml/compiler/qv4bytecodegenerator_p.h
index 0033acf3c7..98951b610c 100644
--- a/src/qml/compiler/qv4bytecodegenerator_p.h
+++ b/src/qml/compiler/qv4bytecodegenerator_p.h
@@ -77,7 +77,9 @@ public:
Label(BytecodeGenerator *generator, LinkMode mode = LinkNow)
: generator(generator),
index(generator->labels.size()) {
- generator->labels.append(mode == LinkNow ? generator->instructions.size() : -1);
+ generator->labels.append(-1);
+ if (mode == LinkNow)
+ link();
}
static Label returnLabel() {
Label l;
@@ -92,6 +94,7 @@ public:
Q_ASSERT(index >= 0);
Q_ASSERT(generator->labels[index] == -1);
generator->labels[index] = generator->instructions.size();
+ generator->clearLastInstruction();
}
BytecodeGenerator *generator = nullptr;
@@ -261,6 +264,11 @@ public:
addJumpInstruction(Instruction::JumpTrue()).link(*trueLabel);
}
+ void clearLastInstruction()
+ {
+ lastInstrType = -1;
+ }
+
private:
friend struct Jump;
friend struct Label;
@@ -292,6 +300,9 @@ private:
int startLine = 0;
int currentLine = 0;
bool debugMode = false;
+
+ int lastInstrType = -1;
+ Moth::Instr lastInstr;
};
}