summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-ssa-simplification.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-05-31 12:36:48 -0700
committerGitHub <noreply@github.com>2023-05-31 12:36:48 -0700
commit5dd401e416e18fdfe904a66284b0cf56cf256ec7 (patch)
tree78c18e41b683261138f1b6349a34057d145a3ae2 /source/slang/slang-ir-ssa-simplification.cpp
parent57f0ab410766374b155fa546c31812d593480048 (diff)
Fix div-by-zero error during sccp. (#2911)
* Diagnose on div-by-zero during sccp. * fix --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-ssa-simplification.cpp')
-rw-r--r--source/slang/slang-ir-ssa-simplification.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/source/slang/slang-ir-ssa-simplification.cpp b/source/slang/slang-ir-ssa-simplification.cpp
index e6c6e353f..66b4ceccb 100644
--- a/source/slang/slang-ir-ssa-simplification.cpp
+++ b/source/slang/slang-ir-ssa-simplification.cpp
@@ -16,7 +16,7 @@ namespace Slang
{
// Run a combination of SSA, SCCP, SimplifyCFG, and DeadCodeElimination pass
// until no more changes are possible.
- void simplifyIR(IRModule* module)
+ void simplifyIR(IRModule* module, DiagnosticSink* sink)
{
bool changed = true;
const int kMaxIterations = 8;
@@ -25,12 +25,16 @@ namespace Slang
while (changed && iterationCounter < kMaxIterations)
{
+ if (sink && sink->getErrorCount())
+ break;
+
changed = false;
+
changed |= hoistConstants(module);
changed |= deduplicateGenericChildren(module);
changed |= propagateFuncProperties(module);
changed |= removeUnusedGenericParam(module);
- changed |= applySparseConditionalConstantPropagationForGlobalScope(module);
+ changed |= applySparseConditionalConstantPropagationForGlobalScope(module, sink);
changed |= peepholeOptimize(module);
for (auto inst : module->getGlobalInsts())
@@ -43,7 +47,7 @@ namespace Slang
while (funcChanged && funcIterationCount < kMaxFuncIterations)
{
funcChanged = false;
- funcChanged |= applySparseConditionalConstantPropagation(func);
+ funcChanged |= applySparseConditionalConstantPropagation(func, sink);
funcChanged |= peepholeOptimize(func);
funcChanged |= removeRedundancyInFunc(func);
funcChanged |= simplifyCFG(func);
@@ -85,15 +89,18 @@ namespace Slang
}
- void simplifyFunc(IRGlobalValueWithCode* func)
+ void simplifyFunc(IRGlobalValueWithCode* func, DiagnosticSink* sink)
{
bool changed = true;
const int kMaxIterations = 8;
int iterationCounter = 0;
while (changed && iterationCounter < kMaxIterations)
{
+ if (sink && sink->getErrorCount())
+ break;
+
changed = false;
- changed |= applySparseConditionalConstantPropagation(func);
+ changed |= applySparseConditionalConstantPropagation(func, sink);
changed |= peepholeOptimize(func);
changed |= removeRedundancyInFunc(func);
changed |= simplifyCFG(func);
@@ -106,6 +113,7 @@ namespace Slang
changed |= constructSSA(func);
iterationCounter++;
+
}
}
}