diff options
| author | Yong He <yonghe@outlook.com> | 2023-06-26 15:18:06 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-26 15:18:06 -0700 |
| commit | 4c9e4de4b68f2612a39e8783e9da89605ecf54e0 (patch) | |
| tree | 83a8efcc45d3d67d07f18caad49a9469252bf509 /source/slang/slang-ir-propagate-func-properties.cpp | |
| parent | 4eef0424a657e19f51f2734ba0199b69ee7354bd (diff) | |
Fix DCE on mutable calls in a loop. (#2943)
* Fix DCE on mutable calls in a loop.
* More accurate in-loop test.
* code review fixes.
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-propagate-func-properties.cpp')
| -rw-r--r-- | source/slang/slang-ir-propagate-func-properties.cpp | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/source/slang/slang-ir-propagate-func-properties.cpp b/source/slang/slang-ir-propagate-func-properties.cpp index 7b29aaf14..f530e263d 100644 --- a/source/slang/slang-ir-propagate-func-properties.cpp +++ b/source/slang/slang-ir-propagate-func-properties.cpp @@ -14,6 +14,26 @@ public: virtual bool propagate(IRBuilder& builder, IRFunc* func) = 0; }; +static bool isKnownOpCodeWithSideEffect(IROp op) +{ + switch (op) + { + case kIROp_ifElse: + case kIROp_unconditionalBranch: + case kIROp_Switch: + case kIROp_Return: + case kIROp_loop: + case kIROp_Call: + case kIROp_Param: + case kIROp_Unreachable: + case kIROp_Store: + case kIROp_SwizzledStore: + return true; + default: + return false; + } +} + class ReadNoneFuncPropertyPropagationContext : public FuncPropertyPropagationContext { public: @@ -40,22 +60,10 @@ public: for (auto inst : block->getChildren()) { // Is this inst known to not have global side effect/analyzable? - if (inst->mightHaveSideEffects()) + if (!isKnownOpCodeWithSideEffect(inst->getOp())) { - switch (inst->getOp()) + if (inst->mightHaveSideEffects()) { - case kIROp_ifElse: - case kIROp_unconditionalBranch: - case kIROp_Switch: - case kIROp_Return: - case kIROp_loop: - case kIROp_Call: - case kIROp_Param: - case kIROp_Unreachable: - case kIROp_Store: - case kIROp_SwizzledStore: - break; - default: // We have a inst that has side effect and is not understood by this method. // e.g. bufferStore, discard, etc. hasSideEffectCall = true; @@ -238,33 +246,21 @@ public: { for (auto inst : block->getChildren()) { - // Is this inst known to not have global side effect/analyzable? - if (inst->mightHaveSideEffects()) + if (!isKnownOpCodeWithSideEffect(inst->getOp())) { - switch (inst->getOp()) + // Is this inst known to not have global side effect/analyzable? + if (inst->mightHaveSideEffects()) { - case kIROp_ifElse: - case kIROp_unconditionalBranch: - case kIROp_Switch: - case kIROp_Return: - case kIROp_loop: - case kIROp_Call: - case kIROp_Param: - case kIROp_Unreachable: - case kIROp_Store: - case kIROp_SwizzledStore: - break; - default: // We have a inst that has side effect and is not understood by this method. // e.g. bufferStore, discard, etc. hasSideEffectCall = true; break; } - } - else - { - // A side effect free inst can't generate side effects for the function. - continue; + else + { + // A side effect free inst can't generate side effects for the function. + continue; + } } if (auto call = as<IRCall>(inst)) |
