Skip to content

[BDCE] Drop nsw/nuw/exact from users of trivialized values - #9030

Open
Natalie Chouinard (sudonatalie) wants to merge 4 commits into
microsoft:mainfrom
sudonatalie:bdce-fix
Open

Natalie Chouinard (sudonatalie) wants to merge 4 commits into
microsoft:mainfrom
sudonatalie:bdce-fix

Conversation

@sudonatalie

Copy link
Copy Markdown
Collaborator

BDCE replaces values that have no live bits with zero, but left nsw/nuw/exact on their users. Those flags no longer held, so later passes could fold the users to wrong constants.

Backports llvm/llvm-project@fe346f9f5be9 (D36592) and its follow-ups llvm/llvm-project@a1067d9baecd and llvm/llvm-project@9e54b7093abd, adapted to BDCE's current state in DXC.

BDCE replaces values that have no live bits with zero, but left
nsw/nuw/exact on their users. Those flags no longer held, so later
passes could fold the users to wrong constants.

Backports llvm/llvm-project@fe346f9f5be9 (D36592) and its follow-ups
llvm/llvm-project@a1067d9baecd and llvm/llvm-project@9e54b7093abd,
adapted to BDCE's current state in DXC.
Copilot AI balanced review requested due to automatic review settings October 14, 2026 18:11
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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

Repeated user-chain traversal introduces quadratic work on chains of zero-demanded instructions.

1 open finding
What changed in this PR

Backports LLVM BDCE fixes to prevent shader miscompilation when dead-bit values are replaced with zero.

Changes:

  • Clears invalid nsw, nuw, and exact flags along affected user chains.
  • Adds an HLSL regression test for incorrect groupshared indexing.
File Description
tools/​clang/​test/​DXC/​Passes/​BDCE/​bdce-trivialized-clears-nuw.hlsl Tests the shader miscompilation regression.
lib/​Transforms/​Scalar/​BDCE.cpp Clears arithmetic flags before replacing dead-bit values.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/Transforms/Scalar/BDCE.cpp Outdated
@damyanp

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

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

Copilot AI balanced review requested due to automatic review settings October 16, 2026 13:40

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 miscompilation fix needs release-note coverage under the repository policy.

0 open findings

1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Low severity Add release note for shader miscompilation fix

lib/​Transforms/​Scalar/​BDCE.cpp:436

Please add a one-sentence entry under ### Upcoming Release → #### Bug Fixes in docs/ReleaseNotes.md. This fixes user-visible shader miscompilation, including an incorrect out-of-range array index, and meets the release-note criteria in CONTRIBUTING.md:115–133. For example: “Fixed incorrect shader results caused by stale overflow and exactness flags after bit-tracking dead code elimination.”

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 16, 2026 14:19

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.

🟢 Approval recommended

No blocking issues remain, and the previously reported repeated-traversal problem is resolved.

0 open findings

🧠 Review effort: Balanced

@@ -0,0 +1,29 @@
// RUN: %dxc -T cs_6_6 -E main %s | FileCheck %s

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Using an end-to-end test to verify correctness of an IR pass change is not ideal. I know this is how DXC had been tested in the past, but for a good while now we've been pushing people to do IR->IR tests for IR pass chagnes.

There is a script ExtractIRForPassTest.py that you can use to extract the IR from an HLSL source prior to a given pass. That should make it straightforward to convert this test case to an IR test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Switched it to an IR test, thanks!

Copilot AI balanced review requested due to automatic review settings October 16, 2026 19:48

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.

🟢 Approval recommended

No unresolved issues remain in the focused implementation, regression coverage, or release notes.

0 open findings

🧠 Review effort: Balanced

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.

4 participants