LLVM21: ARM64 sve2 vector reduce recursion fix - #9396
Closed
mcourteaux wants to merge 2 commits into
Closed
Conversation
… 22. Before LLVM 22, LLVM's llvm.vector.reduce.mul intrinsic lowering isn't available for scalable (SVE) vectors, so CodeGen_LLVM::codegen_vector_reduce always falls back to decomposing VectorReduce::Mul into halving stages for this case (see the `mul_ok` check there). CodeGen_ARM::codegen_across_vector_reduce doesn't know about this: whenever it's re-entered on one of those halving stages, it sees a lane count that isn't a multiple of the native vector width (because the "width" is really an intermediate reduce result, not raw data) and pads it up to a native-width multiply-reduce, which routes back into the same halving decomposition. Padding and halving alternate forever without ever reaching a terminating case, hanging the compiler. Confirmed against a real LLVM 21.1.8 build: the compiler hangs deterministically compiling a VectorReduce::Mul reduction on an SVE2 target before this change, and converges immediately after it. A full sweep of the type/lane/op combinations exercised by test/correctness/vector_reductions.cpp also compiles cleanly with the fix applied. Since the native intrinsic can't be used for this op/target/LLVM-version combination regardless, defer entirely to the base class's decomposition, which does not have this problem. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The previous commit fixes the infinite recursion in CodeGen_ARM::codegen_across_vector_reduce that this skip was working around, so the test no longer needs to be skipped under LLVM < 22. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
5 tasks
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## mcourteaux/llvm21-load-elim-workaround #9396 +/- ##
=======================================================================
Coverage 70.08% 70.09%
=======================================================================
Files 261 261
Lines 79370 79372 +2
Branches 19350 19351 +1
=======================================================================
+ Hits 55629 55633 +4
- Misses 17906 17911 +5
+ Partials 5835 5828 -7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
I think the original approach of disabling SVE2 on LLVM 21 was the right one. There's no reason to believe this is exhaustive. |
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.
Claude Sonnet:
See commit message for more info.
Fixes the hang rediscovered in #9374
Breaking changes
Un-breaking: LLVM 21 works now more?
Checklist