[APX][compiler] Fuse two-way equality branch cascades into a ccmp chain [v8/v8 : main]

0 views
Skip to first unread message

Su, Yihan (Gerrit)

unread,
Aug 13, 2026, 2:11:19 AM (3 days ago) Aug 13
to Jakob Kummerow, Darius Mercadier, chrom...@appspot.gserviceaccount.com, v8-s...@luci-project-accounts.iam.gserviceaccount.com, android-bu...@system.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
Attention needed from Darius Mercadier and Jakob Kummerow

Su, Yihan added 1 comment

Patchset-level comments
File-level comment, Patchset 2 (Latest):
Su, Yihan . resolved

Hi, this patch is a new optimization with using `CCMP`.

Previous, ARM64 and x64 only fuse logical-expression compare chains in the data flow, in this patch, a CFG branch cascade is added, which recognize `if (x==C1) goto T1; else if (x==C2) goto T2; else goto F;`, where the two true edges converge (identical target, or a merge block whose phi inputs match), and fuse it into a single ccmp chain, saving a branch.

PTAL, thanks!

Open in Gerrit

Related details

Attention is currently required from:
  • Darius Mercadier
  • Jakob Kummerow
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: I84cfa0514952ff3128891ecd208a7a2f72220c08
Gerrit-Change-Number: 8239391
Gerrit-PatchSet: 2
Gerrit-Owner: Su, Yihan <yiha...@intel.com>
Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
Gerrit-Reviewer: Jakob Kummerow <jkum...@chromium.org>
Gerrit-Reviewer: Su, Yihan <yiha...@intel.com>
Gerrit-Attention: Darius Mercadier <dmerc...@chromium.org>
Gerrit-Attention: Jakob Kummerow <jkum...@chromium.org>
Gerrit-Comment-Date: Thu, 13 Aug 2026 06:11:14 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

chromeperf@appspot.gserviceaccount.com (Gerrit)

unread,
Aug 13, 2026, 2:59:32 AM (2 days ago) Aug 13
to Su, Yihan, Jakob Kummerow, Darius Mercadier, v8-s...@luci-project-accounts.iam.gserviceaccount.com, android-bu...@system.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
Attention needed from Darius Mercadier, Jakob Kummerow and Su, Yihan

Message from chrom...@appspot.gserviceaccount.com

📍 Job mac-m4-pro-perf/jetstream3.crossbench complete.

See results at: https://pinpoint-dot-chromeperf.appspot.com/job/11a81f91a90000

Open in Gerrit

Related details

Attention is currently required from:
  • Darius Mercadier
  • Jakob Kummerow
  • Su, Yihan
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: I84cfa0514952ff3128891ecd208a7a2f72220c08
Gerrit-Change-Number: 8239391
Gerrit-PatchSet: 2
Gerrit-Owner: Su, Yihan <yiha...@intel.com>
Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
Gerrit-Reviewer: Jakob Kummerow <jkum...@chromium.org>
Gerrit-Reviewer: Su, Yihan <yiha...@intel.com>
Gerrit-Attention: Darius Mercadier <dmerc...@chromium.org>
Gerrit-Attention: Su, Yihan <yiha...@intel.com>
Gerrit-Attention: Jakob Kummerow <jkum...@chromium.org>
Gerrit-Comment-Date: Thu, 13 Aug 2026 06:59:28 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

chromeperf@appspot.gserviceaccount.com (Gerrit)

unread,
Aug 13, 2026, 4:18:42 AM (2 days ago) Aug 13
to Su, Yihan, Jakob Kummerow, Darius Mercadier, v8-s...@luci-project-accounts.iam.gserviceaccount.com, android-bu...@system.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
Attention needed from Darius Mercadier, Jakob Kummerow and Su, Yihan

Message from chrom...@appspot.gserviceaccount.com

📍 Job win-11-perf/jetstream3.crossbench complete.

See results at: https://pinpoint-dot-chromeperf.appspot.com/job/11e40f02a90000

Gerrit-Comment-Date: Thu, 13 Aug 2026 08:18:39 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

Jakob Kummerow (Gerrit)

unread,
Aug 13, 2026, 2:53:32 PM (2 days ago) Aug 13
to Su, Yihan, Jakob Kummerow, Darius Mercadier, chrom...@appspot.gserviceaccount.com, v8-s...@luci-project-accounts.iam.gserviceaccount.com, android-bu...@system.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
Attention needed from Darius Mercadier and Su, Yihan

Jakob Kummerow added 3 comments

Patchset-level comments
Jakob Kummerow . resolved

Looks good, just some nits.

Please add some tests that specifically create the pattern in question, to make sure we have sufficient coverage for exercising this logic. Include some cases that are "almost but not quite" eligible, to make sure we get the decision-making right and don't accidentally change behavior.

Commit Message
Line 9, Patchset 2 (Latest): Recognize the control-flow pattern
Jakob Kummerow . unresolved

nit: no reason to have indentation here (and in lines 15-17).

File src/compiler/backend/instruction-selector.cc
Line 2777, Patchset 2 (Latest):// * Case 1 (visiting Block B): validate, record Block A as a head, turn Block
Jakob Kummerow . unresolved

What are blocks A and B?

Open in Gerrit

Related details

Attention is currently required from:
  • Darius Mercadier
  • Su, Yihan
Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: I84cfa0514952ff3128891ecd208a7a2f72220c08
    Gerrit-Change-Number: 8239391
    Gerrit-PatchSet: 2
    Gerrit-Owner: Su, Yihan <yiha...@intel.com>
    Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
    Gerrit-Reviewer: Jakob Kummerow <jkum...@chromium.org>
    Gerrit-Reviewer: Su, Yihan <yiha...@intel.com>
    Gerrit-Attention: Darius Mercadier <dmerc...@chromium.org>
    Gerrit-Attention: Su, Yihan <yiha...@intel.com>
    Gerrit-Comment-Date: Thu, 13 Aug 2026 18:53:24 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Jakob Kummerow (Gerrit)

    unread,
    Aug 13, 2026, 2:55:56 PM (2 days ago) Aug 13
    to Su, Yihan, Jakob Kummerow, Darius Mercadier, chrom...@appspot.gserviceaccount.com, v8-s...@luci-project-accounts.iam.gserviceaccount.com, android-bu...@system.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
    Attention needed from Darius Mercadier and Su, Yihan

    Jakob Kummerow added 1 comment

    Patchset-level comments
    Jakob Kummerow . resolved

    Also, a high-level question: can you explain why a fused ccmp sequence is expected to be faster? I would have guessed that the traditional sequence makes life easier for the branch predictor.

    Gerrit-Comment-Date: Thu, 13 Aug 2026 18:55:50 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Su, Yihan (Gerrit)

    unread,
    Aug 14, 2026, 3:46:25 AM (yesterday) Aug 14
    to Jakob Kummerow, Darius Mercadier, chrom...@appspot.gserviceaccount.com, v8-s...@luci-project-accounts.iam.gserviceaccount.com, android-bu...@system.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
    Attention needed from Darius Mercadier and Jakob Kummerow

    Su, Yihan added 3 comments

    Patchset-level comments
    Jakob Kummerow . resolved

    Also, a high-level question: can you explain why a fused ccmp sequence is expected to be faster? I would have guessed that the traditional sequence makes life easier for the branch predictor.

    Su, Yihan

    Your intuition isn't wrong — it's just conditional. The honest answer is that the fused form isn't provably faster; it's a favorable expected-value bet. Two points:

      1. You're right that in some regimes the traditional sequence is friendlier to the predictor.
      First, note what the transform actually does — it's not "add a ccmp on top of a good first branch." It's all-or-nothing:
      traditional:  cmp x,C1 ; je T ; cmp x,C2 ; je T   → two branches
    fused: cmp x,C1 ; ccmp x,C2,ne ; je T → one branch on (x==C1)||(x==C2)
      So there's no "first branch" left to help the predictor — both branches are merged into a single one on the OR. When both conditions are highly predictable, the misprediction cost is ≈ 0 for both forms, so the win collapses to
    second-order effects — and there the traditional form has real advantages: the early-out je T lets you skip the second compare on the common path, and it keeps the branch hints (the fused path discards them). In that regime two
    branches can genuinely tie or win.
      2. How to actually account for the ccmp bet.
      The net effect is: spend one always-executed extra compare (ccmp, ~1 cycle) to remove one branch. Removing that branch saves two things:
      - its misprediction risk (a mispredict is ~15–20 cycles), and
    - its front-end footprint — one fewer BTB entry, one fewer taken-branch fetch bubble, tighter code (better uop/I-cache).
      So the trade is:
      (expected mispredict cost + front-end cost of the removed branch)   vs.   one ~1-cycle compare
      Because a mispredict is ~15–20× costlier than the extra compare, the bet pays off as long as the removed branch is mispredicted even occasionally (a few percent), or front-end pressure matters (e.g., a hot loop header). It only loses
    when that branch is almost never mispredicted and the extra compare sits on the critical path and the front end isn't the bottleneck.
      Bottom line: ccmp isn't faster because branches are bad for the predictor; it's faster on average because it converts a possibly-mispredicted, front-end-costly control decision into deterministic data flow that never enters the
    predictor, at the price of one cheap compare. That's positive expected value in typical code but not a guarantee.
    Commit Message
    Line 9, Patchset 2: Recognize the control-flow pattern
    Jakob Kummerow . resolved

    nit: no reason to have indentation here (and in lines 15-17).

    Su, Yihan

    Marked as resolved.

    File src/compiler/backend/instruction-selector.cc
    Line 2777, Patchset 2:// * Case 1 (visiting Block B): validate, record Block A as a head, turn Block
    Jakob Kummerow . resolved

    What are blocks A and B?

    Su, Yihan

    Updated the notes.
    Block A is the head block. Its branch tests `x==C1` with if_true=T1 and if_false=Block B.
    Block B is Block A's if_false successor. Its branch tests `x==C2` with if_true=T2 and if_false=F.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Darius Mercadier
    • Jakob Kummerow
    Submit Requirements:
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: I84cfa0514952ff3128891ecd208a7a2f72220c08
      Gerrit-Change-Number: 8239391
      Gerrit-PatchSet: 4
      Gerrit-Attention: Jakob Kummerow <jkum...@chromium.org>
      Gerrit-Comment-Date: Fri, 14 Aug 2026 07:46:21 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Jakob Kummerow <jkum...@chromium.org>
      unsatisfied_requirement
      open
      diffy

      Jakob Kummerow (Gerrit)

      unread,
      Aug 14, 2026, 7:09:58 AM (yesterday) Aug 14
      to Su, Yihan, Jakob Kummerow, Darius Mercadier, chrom...@appspot.gserviceaccount.com, v8-s...@luci-project-accounts.iam.gserviceaccount.com, android-bu...@system.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
      Attention needed from Darius Mercadier and Su, Yihan

      Jakob Kummerow voted and added 1 comment

      Votes added by Jakob Kummerow

      Code-Review+1

      1 comment

      Patchset-level comments
      File-level comment, Patchset 5 (Latest):
      Jakob Kummerow . resolved

      Thanks, LGTM.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Darius Mercadier
      • Su, Yihan
      Submit Requirements:
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: I84cfa0514952ff3128891ecd208a7a2f72220c08
      Gerrit-Change-Number: 8239391
      Gerrit-PatchSet: 5
      Gerrit-Attention: Su, Yihan <yiha...@intel.com>
      Gerrit-Comment-Date: Fri, 14 Aug 2026 11:09:53 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      unsatisfied_requirement
      open
      diffy

      Jakob Kummerow (Gerrit)

      unread,
      Aug 14, 2026, 7:11:27 AM (yesterday) Aug 14
      to Su, Yihan, Nico Hartmann, Jakob Kummerow, chrom...@appspot.gserviceaccount.com, v8-s...@luci-project-accounts.iam.gserviceaccount.com, android-bu...@system.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
      Attention needed from Nico Hartmann and Su, Yihan

      Jakob Kummerow added 1 comment

      Patchset-level comments
      Jakob Kummerow . resolved

      Redirecting to Nico as Darius is OOO.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Nico Hartmann
      • Su, Yihan
      Submit Requirements:
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: I84cfa0514952ff3128891ecd208a7a2f72220c08
      Gerrit-Change-Number: 8239391
      Gerrit-PatchSet: 5
      Gerrit-Owner: Su, Yihan <yiha...@intel.com>
      Gerrit-Reviewer: Jakob Kummerow <jkum...@chromium.org>
      Gerrit-Reviewer: Nico Hartmann <nicoha...@chromium.org>
      Gerrit-Attention: Nico Hartmann <nicoha...@chromium.org>
      Gerrit-Attention: Su, Yihan <yiha...@intel.com>
      Gerrit-Comment-Date: Fri, 14 Aug 2026 11:11:21 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages