Closed Bug 2092407 Opened 6 days ago Closed 6 days ago

std::atomic operations are not inlined in x86_64 Windows builds with clang 23

Categories

(Firefox Build System :: General, defect)

x86_64
Windows
defect

Tracking

(firefox162 fixed)

RESOLVED FIXED
162 Branch
Tracking Status
firefox162 --- fixed

People

(Reporter: jlink, Assigned: jlink)

References

(Blocks 1 open bug)

Details

(Keywords: perf)

Attachments

(1 external file)

Since VS 2022 17.12, the MSVC STL <atomic> starts with:

// Allow _InterlockedCompareExchange128 to be used:
#if defined(__clang__) && defined(_M_X64) && !defined(_M_ARM64EC)
#pragma clang attribute _STD_ATOMIC_HEADER.push([[gnu::target("cx16")]], apply_to = function)
#endif

That gives every function in the header the cx16 target feature. We do not build with -mcx16. Up to clang 22 this did not matter, but clang 23 refuses to inline those functions into callers that lack the feature. With the same 14.51 headers and flags, a three-line test calling std::atomic<uintptr_t>::fetch_add and fetch_sub:

  • clang 22.1.8: both inlined.
  • clang 23.1.5: not inlined, with -Rpass-missed=inline reporting "should never be inlined (cost=never): conflicting target features".

So with clang 23, every std::atomic / mozilla::Atomic operation on Windows x64 becomes a call to an out-of-line function such as mov rax, rdx; lock xadd [rcx], rax; ret. A local opt build of xul.dll had about 45,000 call sites to the out-of-line fetch_add / fetch_sub alone, and 358 out-of-line STL atomic functions. This covers thread-safe refcounting (ThreadSafeAutoRefCnt, Gecko_AddRefAtom / Gecko_ReleaseAtom) and mozilla::detail::MutexImpl::lock / unlock, which the jemalloc arena locks use. Nightlies from before clang 23 inline these operations.

This is very likely part of the Windows Speedometer 3 regression that got clang 23 (bug 2039813) backed out. Bug 2090871 lists bug 2053035 as its regressor, and both that patch and clang 23 were backed out for it. The alert on the clang 23 backout alone (bug 2039813 comment 8) is what shows clang 23's share: Windows SP3 subtests improving 1-2% and perfstats-MajorGC dropping 7%.

Building with -mcx16 on x86_64 Windows restores inlining: there are no out-of-line STL atomic functions left in xul.dll or mozglue.dll. Every x64 CPU that Windows 10+ supports has cmpxchg16b, and rustc already enables cx16 for x86_64-pc-windows-msvc, so this does not raise our hardware requirements.

Try comparison on a base that still had clang 23, Windows 11 shippable, 20 retriggers:
https://perf.compare/compare-results?baseRev=4a21f991248694f23109c00828d6dd5a45e7efbd&newRev=2f5d9a6dcdee3d0e90b792def2760a8f2104a364&baseRepo=try&newRepo=try&framework=13

  • speedometer3: +1.7% (hw-ref and regular machines), every subtest faster, perfstats-MajorGC -8%
  • speedometer2: +1.8%, MotionMark 1.3: +2.4%, MotionMark HTML +1.0%, StyleBench: +1.3%, WebAudio: -2.2% time
  • No confident regressions

-mcx16 should land before or together with the clang 23 reland.

Assignee: nobody → jlink
OS: Unspecified → Windows
Hardware: Unspecified → x86_64
Flags: needinfo?(mh+mozilla)

The MSVC STL marks every function in <atomic> as target("cx16") under clang,
and clang 23 refuses to inline them into callers built without that feature,
so every std::atomic and mozilla::Atomic operation became an out-of-line call.

Pushed by jlink@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/2f6a5fc44e2f https://hg.mozilla.org/integration/autoland/rev/9de0684778a1 Build with -mcx16 on x86_64 Windows to inline std::atomic operations. r=firefox-build-system-reviewers,glandium
Flags: needinfo?(mh+mozilla)
Status: NEW → RESOLVED
Closed: 6 days ago
Resolution: --- → FIXED
Target Milestone: --- → 162 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: