From 5dd401e416e18fdfe904a66284b0cf56cf256ec7 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 31 May 2023 12:36:48 -0700 Subject: Fix div-by-zero error during sccp. (#2911) * Diagnose on div-by-zero during sccp. * fix --------- Co-authored-by: Yong He --- source/slang/slang-ir-ssa-simplification.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'source/slang/slang-ir-ssa-simplification.cpp') 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++; + } } } -- cgit v1.2.3