summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-redundancy-removal.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-04-28 23:28:23 -0700
committerGitHub <noreply@github.com>2023-04-28 23:28:23 -0700
commitc571bcb025009f9c662e8d631fa49dbfed560287 (patch)
tree3ade836c28920210b3dc1af5e8447d4804dc03ad /source/slang/slang-ir-redundancy-removal.cpp
parent5adecbe837d27cf4e0a554ae13a0338743a8cb4b (diff)
SSA Register Allocation improvements. (#2857)
* SSA Register Allocation improvements. * Fix. * Rename `Use`->`UseOrPseudoUse`. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-redundancy-removal.cpp')
-rw-r--r--source/slang/slang-ir-redundancy-removal.cpp28
1 files changed, 28 insertions, 0 deletions
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<IRLoad>(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;
}