-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve dead/redundant store elimination #38454
Comments
/cc @mkustermann |
Dart objects are allocated null-initialized so initializing stores of null value can be removed from the graph. Issue #38454 Change-Id: I1ba0c3a21462ba8a3409fc648027b4ebf0b1040e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/118286 Reviewed-by: Samir Jindel <sjindel@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
This reverts commit 96b8401. Reason for revert: works incorrectly because kernel-to-il emits multiple initializing stores for the same field. see language_2/field_parameter _test Original change's description: > [vm/compiler] Drop redundant initializing stores of null > > Dart objects are allocated null-initialized so initializing stores of > null value can be removed from the graph. > > Issue #38454 > > Change-Id: I1ba0c3a21462ba8a3409fc648027b4ebf0b1040e > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/118286 > Reviewed-by: Samir Jindel <sjindel@google.com> > Reviewed-by: Martin Kustermann <kustermann@google.com> > Commit-Queue: Vyacheslav Egorov <vegorov@google.com> TBR=vegorov@google.com,kustermann@google.com,sjindel@google.com Change-Id: Ic0c51986168cb51316d3872514719b34cfc780cb No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/118289 Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Dart objects are allocated null-initialized so initializing stores of null value can be removed from the graph. Issue #38454 Change-Id: I692398b67a5f9d27ebc6e6c90c68838c1135de4a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121330 Commit-Queue: Vyacheslav Egorov <vegorov@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
Simple removal of redundant initialising stores have landed and has the following effect
|
Given the guaranteed clearing semantics of allocation, I am looking into D/R(S/L)E improvements that will eliminate both class Bar {
Bar() { a = null; }
Object a;
}
@pragma("vm:never-inline")
Bar foo() {
Bar bar = new Bar();
bar.a = null;
return bar;
}
|
I have been actually pondering on this topic a bit - which made me wonder if our DSE should be merged in the LoadOptimizer which can be made to compute all the necessary information that DSE needs. Additionally LoadOptimizer already computes information about the state of the object fields (for load forwarding) and this is exactly the information that you need to discover redundant stores (i.e. store that stores a value which is already in the field). So it seems natural that this should be handled in the same pass.
I wonder if item nr 4 on the list (null-initialized context allocations - and potentially uninlining context cloning) might yield better size savings then more sophisticated DSE. (at least it looks easier to crunch some numbers on this). |
@mraleph I have implemented the redundant store removal in the LoadOptimizer, and agree that DSE is almost a special case of this optimization now. We can do that refactoring as a follow-up. |
Redundant store elimination yields very modest saving of 13K bytes.
Some more data. When naively doing point (3) above (which actually seems required for backward flowing DSE since we want to keep the first; I did not need it for the forward flowing CSE), this only saves an additional 16 bytes compared to the optimized version above. Removing the two bail-outs in load/store optimizer (which seemed to have been put in place to avoid OOM for some unspecified situations) has no impact, as these cases are not encountered for the gallery. |
We inline allocation of contexts and closures manually so stores which are effectively initializing were not marked as such. Additionally permit elimination of initializing stores into context objects in AOT mode because all contexts are null-initialized there. Bug: #38454 Change-Id: I27886d85160b8600e6e0d38d7bf389d20006fa44 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121849 Commit-Queue: Vyacheslav Egorov <vegorov@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
Rationale: Storing the same value into a field/array is now detected and the redundant store is removed. Note that this is closely related, but not exactly the same as dead store elimination. gallery savings: 13.7K bytes #38454 Change-Id: I57100ef67a8e0132436933226ceecba95825458e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121823 Commit-Queue: Aart Bik <ajcbik@google.com> Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
All four points have been addressed. |
This reverts commit eb87e79. Reason for revert: Multiple configurations are red IRTest_InitializingStores: https://ci.chromium.org/p/dart/builders/ci.sandbox/vm-dartkb-linux-debug-simarm64/1684 https://ci.chromium.org/p/dart/builders/ci.sandbox/vm-dartkb-linux-product-simarm64/1796 http_server_test: https://ci.chromium.org/p/dart/builders/ci.sandbox/vm-kernel-precomp-linux-release-simarm/6796 Original change's description: > [vm/compiler] Mark more stores as initializing. > > We inline allocation of contexts and closures manually so stores > which are effectively initializing were not marked as such. > > Additionally permit elimination of initializing stores into context > objects in AOT mode because all contexts are null-initialized there. > > Bug: #38454 > Change-Id: I27886d85160b8600e6e0d38d7bf389d20006fa44 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121849 > Commit-Queue: Vyacheslav Egorov <vegorov@google.com> > Reviewed-by: Martin Kustermann <kustermann@google.com> TBR=vegorov@google.com,kustermann@google.com Change-Id: I4c2df7b675fa3cdab22a8708440dc45ff3ec3476 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: #38454 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121885 Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
Should this issue be opened again due to c4a7f1c? |
We have relanded the reverted change in: https://dart-review.googlesource.com/c/sdk/+/121982 I forgot to connect it to this issue though. |
At some point we were considering to allocate objects uninitialized - however this is not the case at the moment so any store of
null
into newly allocated object is in fact dead. This issues consists of two several items:null
can simply be dropped (e.g. in the canonicalization pass)LoadOptimizer
can be taught to remove redundant stores (e.g. storing value into a field which already has this value is redundant). This would remove non-initializing stores ofnull
into newly allocated objects.StoreOptimizer::CanEliminateStore
should be revisited because it currently does not eliminate initializing stores - which seems wrong.Context objects can be allocated uninitialized as a performance optimization (all initializing stores are inlined into he caller, which allocates the context). Investigate if this can be changed to align with normal Dart objects for code size reasons.AOT does not lower context allocation - only JIT does./cc @mkustermann
The text was updated successfully, but these errors were encountered: