Skip to content

[202x][unroll] Only run the default LLVM loop unroll for 202x onward - #8822

Open
Farzon Lotfi (farzonl) wants to merge 4 commits into
microsoft:mainfrom
farzonl:feature/202x_unroll-issues-8789
Open

[202x][unroll] Only run the default LLVM loop unroll for 202x onward#8822
Farzon Lotfi (farzonl) wants to merge 4 commits into
microsoft:mainfrom
farzonl:feature/202x_unroll-issues-8789

Conversation

@farzonl

@farzonl Farzon Lotfi (farzonl) commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

resolves #8789

This change maintains the old loop unroll behavior for language modes below 202x.

The 202x unroll behavior is for this to become a hint that is mostly used for O3 optimizations.

We will do this by passing a language-version-derived flag through PassManagerBuilder to DxilLoopUnroll. For HLSL 202x and later, DxilLoopUnroll will leave loops carrying llvm.loop.unroll.count unchanged. The standard unroller may then consume the metadata at -O3. For older language versions, DxilLoopUnroll will continue using the count as an execution limit.

The custom pass will continue handling llvm.loop.unroll.full in every language version. This keeps bare [unroll] behavior and its diagnostics unchanged.

Assisted by GPT 5.6-Sol via Copilot

Copilot AI balanced review requested due to automatic review settings August 24, 2026 19:26

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.

Pull request overview

Updates HLSL 202x [unroll(N)] semantics while preserving legacy behavior.

Changes:

  • Treats unroll counts as optimization hints in HLSL 202x.
  • Adds O2/O3 coverage for fixed and runtime loop counts.
  • Documents the user-visible behavior change.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/clang/test/HLSLFileCheck/hlsl/control_flow/attributes/unroll/count_runtime_hint_202x.hlsl Tests runtime-count loops.
tools/clang/test/HLSLFileCheck/hlsl/control_flow/attributes/unroll/count_less_than_i.hlsl Pins legacy semantics to HLSL 2021.
tools/clang/test/HLSLFileCheck/hlsl/control_flow/attributes/unroll/count_hint_202x.hlsl Tests fixed-count loops.
tools/clang/test/HLSLFileCheck/hlsl/control_flow/attributes/unroll/count_greater_than_i.hlsl Pins legacy semantics to HLSL 2021.
tools/clang/test/HLSLFileCheck/hlsl/control_flow/attributes/unroll/count_cbuff.hlsl Pins runtime legacy behavior to HLSL 2021.
tools/clang/lib/CodeGen/BackendUtil.cpp Derives hint behavior from language version.
lib/Transforms/Scalar/DxilLoopUnroll.cpp Preserves count metadata in HLSL 202x.
lib/Transforms/IPO/PassManagerBuilder.cpp Passes the language-derived setting to unrolling.
include/llvm/Transforms/Scalar.h Extends the pass factory interface.
include/llvm/Transforms/IPO/PassManagerBuilder.h Adds the pass-manager setting.
docs/ReleaseNotes.md Records the language behavior change.

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

Copilot AI review requested due to automatic review settings August 24, 2026 20:19
@farzonl
Farzon Lotfi (farzonl) force-pushed the feature/202x_unroll-issues-8789 branch from 9d355e0 to 7309e06 Compare August 24, 2026 20:19
@farzonl
Farzon Lotfi (farzonl) force-pushed the feature/202x_unroll-issues-8789 branch from 7309e06 to 0a76d68 Compare August 24, 2026 20:20

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 24, 2026 20:22

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread lib/Transforms/IPO/PassManagerBuilder.cpp Outdated
resolves microsoft#8789

This change maintains the old loop unroll behavior for language modes
below 202x.

The 202x unroll behavior is for this to become a hint that is mostly
used for O3 optimizations.

We will do this by passing  a language-version-derived flag through
PassManagerBuilder to DxilLoopUnroll. For HLSL 202x and later,
DxilLoopUnroll will leave loops carrying llvm.loop.unroll.count unchanged.
The standard unroller may then consume the metadata at -O3. For older
language versions, DxilLoopUnroll will continue using the count as an
execution limit.

The custom pass will continue handling llvm.loop.unroll.full in every
language version. This keeps bare [unroll] behavior and its diagnostics
unchanged.
Copilot AI review requested due to automatic review settings August 24, 2026 20:33
@farzonl
Farzon Lotfi (farzonl) force-pushed the feature/202x_unroll-issues-8789 branch from 0a76d68 to b42f0f6 Compare August 24, 2026 20:33

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings August 24, 2026 20:56

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread lib/Transforms/Scalar/DxilLoopUnroll.cpp
Comment thread lib/Transforms/Scalar/DxilLoopUnroll.cpp

@inbelic Finn Plummer (inbelic) left a comment

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.

Makes sense as a hint

@farzonl
Farzon Lotfi (farzonl) marked this pull request as draft August 24, 2026 21:54
@farzonl

Copy link
Copy Markdown
Collaborator Author

Need to investigate the following failures before we take out of draft

    Clang :: DXC/dxopt_test.test
    Clang-Unit :: HLSL/ClangHLSLTests/CompilerTest.BatchHLSL
    Clang-Unit :: HLSL/ClangHLSLTests/CompilerTest.CompileWhenODumpThenOptimizerMatch
    Clang-Unit :: HLSL/ClangHLSLTests/OptimizerTest.OptimizerWhenSlice0ThenOK
    Clang-Unit :: HLSL/ClangHLSLTests/OptimizerTest.OptimizerWhenSlice1ThenOK
    Clang-Unit :: HLSL/ClangHLSLTests/OptimizerTest.OptimizerWhenSlice2ThenOK
    Clang-Unit :: HLSL/ClangHLSLTests/OptimizerTest.OptimizerWhenSlice3ThenOK
    Clang-Unit :: HLSL/ClangHLSLTests/OptimizerTest.OptimizerWhenSliceWithIntermediateOptionsThenOK

@farzonl
Farzon Lotfi (farzonl) marked this pull request as ready for review August 25, 2026 00:22
Copilot AI review requested due to automatic review settings August 25, 2026 00:22

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.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

tools/clang/test/HLSLFileCheck/hlsl/control_flow/attributes/unroll/count_runtime_hint_202x.hlsl:8

  • Use sentence-case capitalization here and remove the trailing whitespace.
// O2 Doesn't unroll and O3 Runtime unrolling only supports 
// power-of-two factors, so the count hint is
// consumed without cloning the loop body.

@llvm-beanz

Copy link
Copy Markdown
Collaborator

Can you also put up a PR to tc57 to add the proposed spec language into the proposal?

We had language in the hlsl-specs draft, but it hasn't been run through the committee yet.

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.

[HLSL 202x] Unroll Attribute

4 participants