Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: f3359ae0f15f798cca7490218a3f5e88b70a6917
      
https://github.com/WebKit/WebKit/commit/f3359ae0f15f798cca7490218a3f5e88b70a6917
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-04-30 (Thu, 30 Apr 2026)

  Changed paths:
    A JSTests/stress/comma-in-condition-context.js
    M Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
    M Source/JavaScriptCore/parser/Nodes.h

  Log Message:
  -----------
  [JSC] Add `emitBytecodeInConditionContext` for comma expression
https://bugs.webkit.org/show_bug.cgi?id=313292

Reviewed by Yusuke Suzuki.

`if ((a, b))` emitted the trailing operand as a value into a temporary
register, then tested it with `jfalse`. When the trailing operand is a
node that has its own condition-context lowering (e.g. `&&`, `||`), the
default path defeats that optimization because the value is forced to
materialize before the test.

Implement CommaNode::emitBytecodeInConditionContext to evaluate the
leading operands in ignore-result position (preserving side effects)
and route the final operand directly through the condition context.
The optimization composes with existing condition-context handling in
LogicalOpNode, LogicalNotNode, and ConditionalNode, so patterns like
`if ((tick(), b && c))`, `while ((step(), cond1 || cond2))`, and
`(log(), a) ? x : y` all benefit automatically.

For trailing operands that already fuse via peephole (e.g. `<`, `===`,
`!`) or that are simple register references, bytecode is unchanged.

Before:
    if ((a, b && c))
    [ 0] enter
    [ 1] mov                loc5, arg2
    [ 4] jfalse             loc5, ->10
    [ 7] mov                loc5, arg3
    [10] jfalse             loc5, ->15
    [13] ret                "T"
    [15] ret                "F"

After:
    [ 0] enter
    [ 1] jfalse             arg2, ->9
    [ 4] jfalse             arg3, ->9
    [ 7] ret                "T"
    [ 9] ret                "F"

Test: JSTests/stress/comma-in-condition-context.js

* JSTests/stress/comma-in-condition-context.js: Added.
(shouldBe):
(testNot):
(testAnd):
(testOr):
(testNested):
(testTernary):
(testTernaryCond):
(testMulti):
(testWhile):
(testFor):
(testDoWhile):
(testRel):
(testEq):
(testNestedComma):
(testOuterAnd):
(testOuterOr):
(testNullish):
(testOrder):
(testOrderMany):
(testOrderInAnd):
(testThrowFirst):
(testThrowLast):
(gen):
(async asyncFn):
(async for):
(testSwitch):
* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::CommaNode::emitBytecodeInConditionContext):
* Source/JavaScriptCore/parser/Nodes.h:

Canonical link: https://commits.webkit.org/312371@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to