Repository navigation
Conversation
`@fastmath` on the sum in two_sum lets the compiler reassociate it. LLVM 23's SLP vectorizer uses that to compute the final hi of a compensated reduction with a tree-shaped vector reduction, while the error terms still come from the sequential partial sums, so the compensation is lost. An error-free transformation needs hi to be exactly fl(a + b). Assisted-by: Claude Code (Opus 5.5)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #43 +/- ##
==========================================
- Coverage 50.11% 47.77% -2.34%
==========================================
Files 13 13
Lines 447 427 -20
==========================================
- Hits 224 204 -20
Misses 223 223 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With Julia built against LLVM 23 (JuliaLang/julia#63626), the compensated summation and dot product tests fail for
Float32: 38 of 636 tests in thesummation/compensatedanddot product/compensatedsets. Over 2200 random ill-conditioned sums (generate_sum(N, 1f5), N = 100:110),sum_orogives:The cause is the
@fastmathon the first line oftwo_sum. It marks that additionfast, which allows reassociation. In the horizontal reduction ofBase.sum(acc::CompSumAcc{<:Vec}), thehivalues form a chains = ((s + x1) + x2) + .... LLVM 23's SLP vectorizer turns that chain into a vector reduction. Because the adds arefast, it computes the finalswith a tree-shapedllvm.vector.reduce.fadd, while the error terms are still derived from the sequential partial sums:The final
hithen no longer matches theloterms. Thefastflag allows this, so it isn't a compiler bug; LLVM 22 just didn't vectorize this chain. An error-free transformation needshito be exactlyfl(a + b).The
@fastmathcame in with a39fd86 as the replacement forSIMDops.@fusible, which only meant "may contract into an FMA".@fastmathallows much more than that (reassociation, no NaN/Inf, no signed zeros), and none of it is safe inside an error-free transformation.With this PR, the test suite passes on LLVM 23 (636/636) and still passes on LLVM 22, both on assertion builds of Julia master and of the LLVM 23 PR. I left the
@fastmathon the error accumulators (acc.e += e). It only reorders the small correction terms, though dropping it would make results independent of vectorization choices.Investigated with the help of Claude Code; reproduced and tested locally.