浏览代码

LibJS/Bytecode: Turn `JumpIf true/false` into unconditional `Jump`

Andreas Kling 1 年之前
父节点
当前提交
ca8dc8f61f
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12 0
      Userland/Libraries/LibJS/Bytecode/Generator.cpp

+ 12 - 0
Userland/Libraries/LibJS/Bytecode/Generator.cpp

@@ -856,6 +856,18 @@ bool Generator::fuse_compare_and_jump(ScopedOperand const& condition, Label true
 
 
 void Generator::emit_jump_if(ScopedOperand const& condition, Label true_target, Label false_target)
 void Generator::emit_jump_if(ScopedOperand const& condition, Label true_target, Label false_target)
 {
 {
+    if (condition.operand().is_constant()) {
+        auto value = m_constants[condition.operand().index()];
+        if (value.is_boolean()) {
+            if (value.as_bool()) {
+                emit<Op::Jump>(true_target);
+            } else {
+                emit<Op::Jump>(false_target);
+            }
+            return;
+        }
+    }
+
     // NOTE: It's only safe to fuse compare-and-jump if the condition is a temporary with no other dependents.
     // NOTE: It's only safe to fuse compare-and-jump if the condition is a temporary with no other dependents.
     if (condition.operand().is_register()
     if (condition.operand().is_register()
         && condition.ref_count() == 1
         && condition.ref_count() == 1