From c571bcb025009f9c662e8d631fa49dbfed560287 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 28 Apr 2023 23:28:23 -0700 Subject: SSA Register Allocation improvements. (#2857) * SSA Register Allocation improvements. * Fix. * Rename `Use`->`UseOrPseudoUse`. --------- Co-authored-by: Yong He --- source/slang/slang-ir-redundancy-removal.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source/slang/slang-ir-redundancy-removal.cpp') diff --git a/source/slang/slang-ir-redundancy-removal.cpp b/source/slang/slang-ir-redundancy-removal.cpp index 32c6abd39..37e8ba5bb 100644 --- a/source/slang/slang-ir-redundancy-removal.cpp +++ b/source/slang/slang-ir-redundancy-removal.cpp @@ -345,6 +345,34 @@ bool tryRemoveRedundantStore(IRGlobalValueWithCode* func, IRStore* store) store->removeAndDeallocate(); return true; } + + // A store can be removed if it is a store into the same var, and there are + // no side effects between the load of the var and the store of the var. + if (auto load = as(store->getVal())) + { + if (load->getPtr() == store->getPtr()) + { + if (load->getParent() == store->getParent()) + { + bool valueMayChange = false; + for (auto inst = load->next; inst; inst = inst->next) + { + if (inst == store) + break; + if (canInstHaveSideEffectAtAddress(func, inst, store->getPtr())) + { + valueMayChange = true; + break; + } + } + if (!valueMayChange) + { + store->removeAndDeallocate(); + return true; + } + } + } + } return false; } -- cgit v1.2.3