Skip to content

[Reassociate] Bail out when 16-bit rank fields overflow - #9113

Open
Steven Perron (s-perron) wants to merge 2 commits into
microsoft:mainfrom
s-perron:fix-reassociate-bail-on-rank-overflow
Open

Steven Perron (s-perron) wants to merge 2 commits into
microsoft:mainfrom
s-perron:fix-reassociate-bail-on-rank-overflow

Conversation

@s-perron

Copy link
Copy Markdown
Collaborator

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.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread lib/Transforms/Scalar/Reassociate.cpp Resolved
Comment thread lib/Transforms/Scalar/Reassociate.cpp Resolved
Comment thread lib/Transforms/Scalar/Reassociate.cpp Resolved
Copilot AI balanced review requested due to automatic review settings November 12, 2026 18:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The user-visible reassociation rank-overflow fix lacks the release-note entry required by the contribution policy.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@s-perron
Steven Perron (s-perron) force-pushed the fix-reassociate-bail-on-rank-overflow branch from f96f4cd to 31db625 Compare November 12, 2026 18:55
Copilot AI balanced review requested due to automatic review settings November 12, 2026 18:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The fix for a user-visible reassociation miscompile lacks the bug-fix release note required by CONTRIBUTING.md.

No open issues 🎉

Review effort: Balanced

@s-perron

Copy link
Copy Markdown
Collaborator Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

3 participants