You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In HLSL 202X the DXC implementation of the loop unroll factor should no longer alter the number of iteration executions. Ideally the loop unroll factor will also become a compiler hint for partial loop unroll. If this can not be done because of concerns of invalid DXIL generation then the loop unroll factor as a feature should be removed from DXC. Removal in this case means ignoring the unroll factor and issuing a warning to inform the user.
From what I am seeing in DXC we actually do two different loop unrolls. one is the standard loop unroll that exists in clang and the other is a custom loop unroll that preempts the default one and runs first that can change loop execution behavior. The default one seems to only kick in on -O3 while the HLSL one works at all optimization levels. the default one then only really kicks in if the hlsl loop unroll does not impact loop execution and if we are doing the highest level of optimization
Looking at the DXC code is giving me some new perspectice. if we just turn off the HLSL loop unroll then we also have to accept that the compiler might not unroll and likely won't unless you do O3. I think that should be fine because it is what clang does.
The good news. I thinkit should be easier to do this feature than we originally though.
As I said earlier, the HLSL optimization pipeline currently runs two unrollers:
DxilLoopUnroll, which implements required HLSL full unrolling and the
legacy counted-loop behavior.
LLVM's standard loop-unroll pass at -O3, which understands llvm.loop.unroll.count as a partial-unroll hint and preserves residual
iterations.
Implementation
The implementation will pass 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.
Activity
farzonl commentedon Aug 19, 2026
From what I am seeing in DXC we actually do two different loop unrolls. one is the standard loop unroll that exists in clang and the other is a custom loop unroll that preempts the default one and runs first that can change loop execution behavior. The default one seems to only kick in on
-O3while the HLSL one works at all optimization levels. the default one then only really kicks in if the hlsl loop unroll does not impact loop execution and if we are doing the highest level of optimizationLooking at the DXC code is giving me some new perspectice. if we just turn off the HLSL loop unroll then we also have to accept that the compiler might not unroll and likely won't unless you do O3. I think that should be fine because it is what clang does.
The good news. I thinkit should be easier to do this feature than we originally though.
farzonl commentedon Aug 19, 2026
Here is the behavior I think we will do for DXC
[unroll(N)], HLSL 2021 or earlier[unroll(N)], HLSL 202x or later,-O3Nas a requested partial-unroll factor while preserving the loop termination condition. The optimizer may decline or adjust the request.[unroll(N)], HLSL 202x or later, below-O3[unroll], any language version[loop], any language versionfarzonl commentedon Aug 19, 2026
As I said earlier, the HLSL optimization pipeline currently runs two unrollers:
DxilLoopUnroll, which implements required HLSL full unrolling and thelegacy counted-loop behavior.
-O3, which understandsllvm.loop.unroll.countas a partial-unroll hint and preserves residualiterations.
Implementation
The implementation will pass a language-version-derived flag through
PassManagerBuildertoDxilLoopUnroll. For HLSL 202x and later,DxilLoopUnrollwill leave loops carryingllvm.loop.unroll.countunchanged.The standard unroller may then consume the metadata at
-O3. For olderlanguage versions,
DxilLoopUnrollwill continue using the count as anexecution limit.
The custom pass will continue handling
llvm.loop.unroll.fullin everylanguage version. This keeps bare
[unroll]behavior and its diagnosticsunchanged.
[202x][unroll] Only run the default LLVM loop unroll for 202x onward
[202x][unroll] Only run the default LLVM loop unroll for 202x onward
[202x][unroll] Only run the default LLVM loop unroll for 202x onward
[202x][unroll] Only run the default LLVM loop unroll for 202x onward
[202x][unroll] Only run the default LLVM loop unroll for 202x onward (m…