From 259a015feb9d4ab65e8fbba32f6c777e92780cc7 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 22 Mar 2023 21:16:35 -0700 Subject: Type legalization and autodiff bug fixes. (#2722) * Bug fixes. * Fix. * Only perform autodiff for functions whose derivative is actually used. * Fix loop optimize bug. * Fix high order diff. * Fix trivial diff func generation. * Fixes. * Cleanup. --------- Co-authored-by: Yong He --- source/slang/slang-ir-simplify-cfg.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'source/slang/slang-ir-simplify-cfg.cpp') diff --git a/source/slang/slang-ir-simplify-cfg.cpp b/source/slang/slang-ir-simplify-cfg.cpp index b814442fa..e98d14a0c 100644 --- a/source/slang/slang-ir-simplify-cfg.cpp +++ b/source/slang/slang-ir-simplify-cfg.cpp @@ -105,7 +105,7 @@ static bool doesLoopHasSideEffect(IRGlobalValueWithCode* func, IRLoop* loopInst) loopBlocks.Add(b); auto addressHasOutOfLoopUses = [&](IRInst* addr) { - // The entire access chain of `addr` must have no uses out side the loop. + // The entire access chain of `addr` must have no uses outside the loop. // The root variable must be a local var. for (auto chainNode = addr; chainNode;) { @@ -123,6 +123,11 @@ static bool doesLoopHasSideEffect(IRGlobalValueWithCode* func, IRLoop* loopInst) chainNode = chainNode->getOperand(0); continue; case kIROp_Var: + if (auto rate = chainNode->getFullType()->getRate()) + { + if (!as(rate)) + return true; + } break; default: return true; @@ -143,10 +148,6 @@ static bool doesLoopHasSideEffect(IRGlobalValueWithCode* func, IRLoop* loopInst) return true; } - // The inst can't possibly have side effect? Skip it. - if (!inst->mightHaveSideEffects()) - continue; - // This inst might have side effect, try to prove that the // side effect does not leak beyond the scope of the loop. if (auto call = as(inst)) @@ -187,6 +188,10 @@ static bool doesLoopHasSideEffect(IRGlobalValueWithCode* func, IRLoop* loopInst) } else { + // The inst can't possibly have side effect? Skip it. + if (!inst->mightHaveSideEffects()) + continue; + // For all other insts, we assume it has a global side effect. return true; } -- cgit v1.2.3