MarshallOfSound

#51848: build: disable LLVM unroll-add-parallel-reductions on Apple targets

Merged
Created: Jun 2, 2026, 12:02:06 PM
Merged: Jun 2, 2026, 3:56:59 PM
4 comments
Target: main

LLVM's loop unroller miscompiles sub-form reductions when introducing parallel reduction phis (llvm/llvm-project#201065): the partial accumulators are recombined with alternating signs instead of being summed. Under ThinLTO + PGO this miscompiles simdutf's arm64 utf8_length_from_latin1 in darwin-arm64/mas-arm64 release builds, undercounting UTF-8 lengths for Latin-1 strings.

On Apple Silicon this manifests as (shipped in v42.3.1):

  • Buffer.byteLength() returning values 2 bytes short for one-byte strings >= 64 chars containing U+0080-U+00FF characters at affected offsets
  • silently truncated Buffer.from(string) / TextEncoder.encode() results
  • a heap buffer overflow followed by a CHECK crash in node::Utf8Value (e.g. fs.writeFileSync with such strings >= ~1KB)

LLVM only enables the parallel-reduction unrolling for Apple M-like CPUs (getAppleRuntimeUnrollPreferences), so only Apple targets are affected; linux-arm64 and win-arm64 target generic CPUs and cannot hit this. The flag is applied at link time, where ThinLTO backend codegen runs, and is inert on branches without macOS ThinLTO.

Validated on a local release build with the exact CI configuration (ThinLTO + Electron PGO profile): the crash and corruption repros disappear with the flag, the affected loop remains unrolled (single accumulator), and Speedometer 3.1 is unchanged (-0.84%, p=0.48, interleaved A/B).

This patch can be removed once the upstream fix (llvm/llvm-project#201066) ships in the bundled clang.

Notes: Fixed silent data truncation in Buffer/TextEncoder APIs and a crash in fs.writeFileSync with non-ASCII strings on Apple Silicon.

Backports

41-x-y
Merged
PR Number
#51851
Merged At
Jun 3, 2026, 1:53:55 PM
Released In
v41.7.2
Release Date
Jun 9, 2026, 11:00:18 AM
42-x-y
Merged
PR Number
#51849
Merged At
Jun 3, 2026, 2:18:11 PM
Released In
v42.3.3
Release Date
Jun 3, 2026, 2:18:37 PM
43-x-y
Merged
PR Number
#51850
Merged At
Jun 2, 2026, 5:02:11 PM
Released In
v43.0.0-beta.1
Release Date
Jun 4, 2026, 3:31:55 PM

Semver Impact

Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.

Semantic Versioning helps users understand the impact of updates:

  • Major (X.y.z): Breaking changes that may require code modifications
  • Minor (x.Y.z): New features that maintain backward compatibility
  • Patch (x.y.Z): Bug fixes that don't change the API
  • None: Changes that don't affect using facing parts of Electron