diff options
| author | Yong He <yonghe@outlook.com> | 2023-10-25 12:21:35 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-25 12:21:35 -0700 |
| commit | e04abb54bc69d90a503852d60a89e8bac7b60ec8 (patch) | |
| tree | fdeedbda67c631cd8a8621921a1484c0ecf5ca6f | |
| parent | 017534601e86df53c0669be7dbc6c565d2108be6 (diff) | |
Fix single iteration loop detection logic. (#3287)
Co-authored-by: Yong He <yhe@nvidia.com>
| -rw-r--r-- | source/slang/slang-ir-simplify-cfg.cpp | 4 | ||||
| -rw-r--r-- | tests/ir/loop-unroll-simplify.slang | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/source/slang/slang-ir-simplify-cfg.cpp b/source/slang/slang-ir-simplify-cfg.cpp index 0fe752c8f..127a515ce 100644 --- a/source/slang/slang-ir-simplify-cfg.cpp +++ b/source/slang/slang-ir-simplify-cfg.cpp @@ -97,8 +97,8 @@ static bool isTrivialSingleIterationLoop( { if (!context.domTree->dominates(loop->getParent(), branchTarget)) return false; - if (targetBlock != loop->getBreakBlock()) - return false; + if (branchTarget != loop->getBreakBlock()) + continue; if (findBreakableRegionHeaderInst(context.domTree, block) != loop) { // If the break is initiated from a nested region, this is not trivial. diff --git a/tests/ir/loop-unroll-simplify.slang b/tests/ir/loop-unroll-simplify.slang new file mode 100644 index 000000000..f935b8b1e --- /dev/null +++ b/tests/ir/loop-unroll-simplify.slang @@ -0,0 +1,14 @@ +//TEST:SIMPLE(filecheck=CHECK): -entry main -target hlsl -profile cs_6_3 + +RWStructuredBuffer<int> output; + +void main() +{ + // Test that the unrolled code does not have trivial single iteration loops. + // CHECK-NOT: break + [ForceUnroll] + for (int i = 0; i < 2; i++) + { + output[i] = i; + } +} |
