[202x][unroll] Only run the default LLVM loop unroll for 202x onward - #8822
[202x][unroll] Only run the default LLVM loop unroll for 202x onward#8822Farzon Lotfi (farzonl) wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
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.
9d355e0 to
7309e06
Compare
7309e06 to
0a76d68
Compare
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.
0a76d68 to
b42f0f6
Compare
Finn Plummer (inbelic)
left a comment
There was a problem hiding this comment.
Makes sense as a hint
|
Need to investigate the following failures before we take out of draft |
There was a problem hiding this comment.
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.
|
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. |
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