From b61be5e6fb7fe1c4ec8228cdf73f49f11e5a0ac9 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:47:58 -0400 Subject: Assorted auto-diff enhancements for increased performance & more streamlined auto-diff results (#5394) * Various AD enhancements * Fix issue with pt-loop test * Update pt-loop.slang * More fixes for perf. Final minimal context test now passes. * Fix issue with loop-elimination pass not running after dce * Try fix wgpu test by removing select operator * Disable wgpu * Delete out.wgsl * Remove comments * Update slang-ir-util.cpp * Fix header relative paths for slang-embed * Disbale wgpu for a few other tests * Better way of determining which params to ignore for side-effects * Update slang-ir-dce.cpp * Fix issue with circular reference from previous AD pass being left behind for the next AD pass * Update slang-ir-dce.cpp --- source/slang/slang-ir-util.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-ir-util.cpp') diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index f81cde30b..b0eeca4dd 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -971,12 +971,41 @@ void setInsertAfterOrdinaryInst(IRBuilder* builder, IRInst* inst) } } +IRInst* tryFindBasePtr(IRInst* inst, IRInst* parentFunc) +{ + // Keep going up the tree until we find a variable. + switch (inst->getOp()) + { + case kIROp_Var: + return getParentFunc(inst) == parentFunc ? inst : nullptr; + case kIROp_Param: + return getParentFunc(inst) == parentFunc ? inst : nullptr; + case kIROp_GetElementPtr: + return tryFindBasePtr(as(inst)->getBase(), parentFunc); + case kIROp_FieldAddress: + return tryFindBasePtr(as(inst)->getBase(), parentFunc); + default: + return nullptr; + } +} + bool areCallArgumentsSideEffectFree(IRCall* call, SideEffectAnalysisOptions options) { // If the function has no side effect and is not writing to any outputs, // we can safely treat the call as a normal inst. + IRFunc* parentFunc = nullptr; - for (UInt i = 0; i < call->getArgCount(); i++) + + IRParam* param = nullptr; + if (auto calleeFunc = getResolvedInstForDecorations(call->getCallee())) + { + if (auto block = calleeFunc->getFirstBlock()) + { + param = block->getFirstParam(); + } + } + + for (UInt i = 0; i < call->getArgCount(); i++, (param = param ? param->getNextParam() : nullptr)) { auto arg = call->getArg(i); if (isValueType(arg->getDataType())) @@ -1074,6 +1103,9 @@ bool areCallArgumentsSideEffectFree(IRCall* call, SideEffectAnalysisOptions opti } else { + if (param && param->findDecoration()) + continue; + return false; } } @@ -1107,6 +1139,7 @@ bool doesCalleeHaveSideEffect(IRInst* callee) { case kIROp_NoSideEffectDecoration: case kIROp_ReadNoneDecoration: + case kIROp_IgnoreSideEffectsDecoration: return false; } } -- cgit v1.2.3