Repository navigation
[Reassociate] Bail out when 16-bit rank fields overflow - #9113
Open
Steven Perron (s-perron) wants to merge 2 commits into
Open
Steven Perron (s-perron) wants to merge 2 commits into
Steven Perron (s-perron) wants to merge 2 commits into
Conversation
Skip reassociation on functions whose argument count, basic-block count, or per-block unmovable instruction count exceeds the 16-bit fields packed into 32-bit ranks by BuildRankMap. In rank-overflow.ll, without bailing out, rank wraparound gives %l1 and %l2 the same rank across an intervening store, causing Reassociate to cancel %l1 - %l2 and fold (%base + %l1) - %l2 to %base.
Steven Perron (s-perron)
requested review from
Natalie Chouinard (sudonatalie)
and
a balanced review from Copilot
November 10, 2026 15:25
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The argument-count bailout lacks regression coverage for overflow and partial-map cleanup, and the user-visible wrong-code fix is missing a required release note.
2 open issues
What changed in this PR
This PR prevents incorrect compiler results from Reassociate rank overflow by skipping functions whose ranks exceed the packed 16-bit fields.
Changes:
- Add overflow checks for argument, basic-block, and per-block unmovable-instruction ranks.
- Clear partially built rank maps when skipping reassociation.
- Add instruction- and block-overflow regressions, checking that subsequent small functions still optimize.
| File | Description |
|---|---|
tools/clang/test/DXC/Passes/reassociate/rank-overflow.ll |
Tests overflow bailouts and continued optimization of a small function. |
lib/Transforms/Scalar/Reassociate.cpp |
Detects rank overflow and skips reassociation with map cleanup. |
Review effort: Balanced
Natalie Chouinard (sudonatalie)
approved these changes
Nov 11, 2026
Steven Perron (s-perron)
force-pushed
the
fix-reassociate-bail-on-rank-overflow
branch
from
November 12, 2026 18:55
f96f4cd to
31db625
Compare
Collaborator
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
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.


Skip reassociation on functions whose argument count, basic-block count,
or per-block unmovable instruction count exceeds the 16-bit fields packed
into 32-bit ranks by BuildRankMap.
In rank-overflow.ll, without bailing out, rank wraparound gives %l1 and
%l2 the same rank across an intervening store, causing Reassociate to
cancel %l1 - %l2 and fold (%base + %l1) - %l2 to %base.