diff options
| author | Yong He <yonghe@outlook.com> | 2024-01-23 19:37:10 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-23 19:37:10 -0800 |
| commit | ad45062fcc76cd622aaa1a9cb00515d42f8d3528 (patch) | |
| tree | 28a54911021d4e3c8cd69dc47f67b8f39cdb310a /source/slang/slang-ir-spirv-legalize.cpp | |
| parent | 1c1d096234d43b2bcb33c2438a6626831bd4e0aa (diff) | |
SPIRV Legalization fixes. (#3479)
* Fix CFG legalization for SPIRV backend.
* Emit DepthReplacing execution mode.
* Fix do-while lowering.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-spirv-legalize.cpp')
| -rw-r--r-- | source/slang/slang-ir-spirv-legalize.cpp | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/source/slang/slang-ir-spirv-legalize.cpp b/source/slang/slang-ir-spirv-legalize.cpp index c4b0a471a..81bec8aa7 100644 --- a/source/slang/slang-ir-spirv-legalize.cpp +++ b/source/slang/slang-ir-spirv-legalize.cpp @@ -19,6 +19,7 @@ #include "slang-ir-simplify-cfg.h" #include "slang-ir-peephole.h" #include "slang-ir-redundancy-removal.h" +#include "slang-ir-loop-unroll.h" namespace Slang { @@ -1125,23 +1126,11 @@ struct SPIRVLegalizationContext : public SourceEmitterBase // - the back-edge block must structurally post dominate the // Continue Target - // If the continue block has only a single predecessor, pretend like it - // is just ordinary control flow - // - // TODO: could this fail in cases like this, where it had a single - // predecessor, but it's still nested inside a region? - // do{ - // if(x) - // continue; - // unreachable - // } while(foo) + // By this point, we should have already eliminated all continue jumps and + // turned them into a break jump. So all loop insts should satisfy + // continueBlock == targetBlock. const auto t = loop->getTargetBlock(); auto c = loop->getContinueBlock(); - if(c->getPredecessors().getCount() <= 1) - { - c = t; - loop->continueBlock.set(c); - } // Our IR allows multiple back-edges to a loop header if this is also // the loop continue block. SPIR-V does not so replace them with a @@ -1565,6 +1554,9 @@ struct SPIRVLegalizationContext : public SourceEmitterBase case kIROp_SPIRVAsm: processSPIRVAsm(as<IRSPIRVAsm>(inst)); break; + case kIROp_Func: + eliminateContinueBlocksInFunc(m_module, as<IRFunc>(inst)); + [[fallthrough]]; default: for (auto child = inst->getLastChild(); child; child = child->getPrevInst()) { @@ -1826,7 +1818,10 @@ void simplifyIRForSpirvLegalization(TargetRequest* target, DiagnosticSink* sink, funcChanged |= applySparseConditionalConstantPropagation(func, sink); funcChanged |= peepholeOptimize(target, func); funcChanged |= removeRedundancyInFunc(func); - funcChanged |= simplifyCFG(func, CFGSimplificationOptions::getFast()); + CFGSimplificationOptions options; + options.removeTrivialSingleIterationLoops = true; + options.removeSideEffectFreeLoops = false; + funcChanged |= simplifyCFG(func, options); eliminateDeadCode(func); } } |
