VOOZH about

URL: https://bugzilla.mozilla.org/2032275

⇱ 2032275 - arm64: Emit tbnz/tbz for sign-bit branch tests in branchTest32/branchTestPtr


Closed Bug 2032275 Opened 2 months ago Closed 1 month ago

arm64: Emit tbnz/tbz for sign-bit branch tests in branchTest32/branchTestPtr

arm64: Emit tbnz/tbz for sign-bit branch tests in branchTest32/branchTestPtr
Core
JavaScript Engine: JIT
Trunk
Unspecified
Unspecified
enhancement
Points:
---
RESOLVED FIXED
RESOLVED
FIXED
152 Branch
Iteration:
---
a11y-review
Accessibility Severity
Performance Impact
Size Estimate
Webcompat Priority
Webcompat Score
Tracking Status
firefox151 --- wontfix
firefox152 --- fixed
Tracking Status
relnote-firefox
thunderbird_esr115
thunderbird_esr140
firefox-esr115
firefox-esr140
firefox-esr153
firefox151
firefox152
firefox153
firefox154
---
QA Whiteboard:
[qa-triage-done-c153/b152]
Has STR:
---
Change Request:
---
Bug Flags:
Signature:
None
This bug is publicly visible.

 
Assignee

Description

β€’
2 months ago

branchTest32 and branchTestPtr in MacroAssembler-arm64-inl.h already recognize the test reg, reg idiom (where lhs == rhs) and emit cbz/cbnz for the Zero/NonZero conditions. However, the Signed/NotSigned conditions fall through to the generic path, which emits two instructions:

tst w0, w0
b.mi label

This patch extends the existing pattern to also handle Signed and NotSigned, emitting a single tbnz/tbz on the sign bit instead:

tbnz w0, #31, label (32-bit Signed)
tbz w0, #31, label (32-bit NotSigned)
tbnz x0, #63, label (64-bit Signed)
tbz x0, #63, label (64-bit NotSigned)

This saves one instruction per call site, avoids clobbering NZCV flags, and matches what LLVM already emits for equivalent sign-bit tests in AOT-compiled code (where sign-bit tbz/tbnz account for 1-4% of all instructions in typical arm64 binaries).

Call sites that benefit include visitModPowTwoI, visitModPowTwoI64, bailoutTest32(Signed, ...), and any other path through branchTest{32,Ptr}(Signed/NotSigned, r, r, ...).

Range safety: tbnz/tbz have a Β±32KB offset (14-bit immediate), tighter than b.cc's Β±1MB. Mozilla's vixl fork handles this via registerBranchDeadline with automatic veneer insertion, so arbitrarily distant labels degrade gracefully to a 2-instruction trampoline β€” no worse than the original code.

Verified with IONFLAGS=codegen that Ion emits tbnz/tbz for the targeted patterns. ./mach jit-test passes.

Assignee

Comment 1

β€’
2 months ago

Extend branchTest32/branchTestPtr to recognize the (Signed/NotSigned, r, r)
pattern and emit a single tbnz/tbz on bit 31/63 instead of tst + b.mi/b.pl.

Assignee: nobody β†’ andrew
Status: NEW β†’ ASSIGNED
Blocks: arm64-ion
Severity: -- β†’ N/A
Priority: -- β†’ P1

Comment 3

β€’
1 month ago
bugherder
Status: ASSIGNED β†’ RESOLVED
Closed: 1 month ago
Resolution: --- β†’ FIXED
Target Milestone: --- β†’ 152 Branch
QA Whiteboard: [qa-triage-done-c153/b152]
You need to log in before you can comment on or make changes to this bug.