mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:07:34 +00:00
LibJS/Bytecode: Add peephole optimization pass and fuse compare+jump
This patch adds a new "Peephole" pass for performing small, local optimizations to bytecode. We also introduce the first such optimization, fusing a sequence of some comparison instruction FooCompare followed by a JumpIf into a new set of JumpFooCompare instructions. This gives a ~50% speed-up on the following microbenchmark: for (let i = 0; i < 10_000_000; ++i) { } But more traditional benchmarks see a pretty sizable speed-up as well, for example 15% on Kraken/ai-astar.js and 16% on Kraken/audio-dft.js :^)
This commit is contained in:
parent
acd29e064c
commit
4438ec481c
8 changed files with 214 additions and 24 deletions
|
@ -1123,6 +1123,40 @@ private:
|
|||
Operand m_condition;
|
||||
};
|
||||
|
||||
// NOTE: The raw operator is used for comparing two Int32 values.
|
||||
#define JS_ENUMERATE_FUSABLE_BINARY_OPS(X) \
|
||||
X(GreaterThan, >, greater_than) \
|
||||
X(GreaterThanEquals, >=, greater_than_equals) \
|
||||
X(LessThan, <, less_than) \
|
||||
X(LessThanEquals, <=, less_than_equals) \
|
||||
X(LooselyEquals, ==, loosely_equals) \
|
||||
X(LooselyInequals, !=, loosely_inequals) \
|
||||
X(StrictlyEquals, ==, strict_equals) \
|
||||
X(StrictlyInequals, !=, strict_inequals)
|
||||
|
||||
#define JS_DECLARE_FUSED_JUMP(PreOp, ...) \
|
||||
class Jump##PreOp final : public Jump { \
|
||||
public: \
|
||||
explicit Jump##PreOp(Operand lhs, Operand rhs, Label true_target, Label false_target) \
|
||||
: Jump(Type::Jump##PreOp, move(true_target), move(false_target), sizeof(*this)) \
|
||||
, m_lhs(lhs) \
|
||||
, m_rhs(rhs) \
|
||||
{ \
|
||||
} \
|
||||
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
|
||||
ByteString to_byte_string_impl(Bytecode::Executable const&) const; \
|
||||
\
|
||||
Operand lhs() const { return m_lhs; } \
|
||||
Operand rhs() const { return m_rhs; } \
|
||||
\
|
||||
private: \
|
||||
Operand m_lhs; \
|
||||
Operand m_rhs; \
|
||||
};
|
||||
|
||||
JS_ENUMERATE_FUSABLE_BINARY_OPS(JS_DECLARE_FUSED_JUMP)
|
||||
#undef JS_DECLARE_FUSED_JUMP
|
||||
|
||||
class JumpNullish final : public Jump {
|
||||
public:
|
||||
explicit JumpNullish(Operand condition, Label true_target, Label false_target)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue