Skip to content

[SSADestroyHoisting] Split destroy from copy. #41497

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

Conversation

nate-chandler
Copy link
Contributor

[SSADestroyHoisting] Split destroy from copy.

As was done with store [init], transform instructions like

copy_addr %n to %m

into the sequence

destroy_addr %m
copy_addr %n to [initialization] %m

in order to create more opportunities for hoisting destroys.

After hoisting, if these opportunities for hoisting don't result in hoisting actually occurring, recombine the two instructions.

As was done with store [init], transform instructions like

    copy_addr %n to %m

into the sequence

    destroy_addr %m
    copy_addr %n to [initialization] %m

in order to create more opportunities for hoisting destroys.

After hoisting, if these opportunities for hoisting don't result in
hoisting actually occurring, recombine the two instructions.
@nate-chandler nate-chandler marked this pull request as draft February 21, 2022 17:22
@nate-chandler nate-chandler requested a review from atrick February 21, 2022 17:22
@nate-chandler
Copy link
Contributor Author

@swift-ci please benchmark

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

------- Performance (x86_64): -O -------

REGRESSION                                 OLD    NEW    DELTA    RATIO
ConvertFloatingPoint.MockFloat64Exactly2   14     16     +14.3%   **0.88x (?)**

IMPROVEMENT                                OLD    NEW    DELTA    RATIO
FlattenListLoop                            1595   961    -39.7%   **1.66x (?)**
FlattenListFlatMap                         4114   3300   -19.8%   **1.25x (?)**
Breadcrumbs.MutatedIdxToUTF16.Mixed        223    191    -14.3%   **1.17x (?)**
Breadcrumbs.MutatedUTF16ToIdx.Mixed        217    188    -13.4%   **1.15x (?)**
Calculator                                 160    141    -11.9%   **1.13x (?)**
OpenClose                                  58     52     -10.3%   **1.12x (?)**

------- Code size: -O -------

------- Performance (x86_64): -Osize -------

REGRESSION                            OLD    NEW    DELTA    RATIO
UTF8Decode_InitDecoding               125    137    +9.6%    **0.91x (?)**
SetUnionInt50                         63     68     +7.9%    **0.93x (?)**

IMPROVEMENT                           OLD    NEW    DELTA    RATIO
ObjectiveCBridgeStubFromNSString      772    626    -18.9%   **1.23x (?)**
Breadcrumbs.MutatedIdxToUTF16.Mixed   223    191    -14.3%   **1.17x (?)**
Breadcrumbs.MutatedUTF16ToIdx.Mixed   219    188    -14.2%   **1.16x (?)**
Calculator                            158    138    -12.7%   **1.14x (?)**
Chars2                                3450   3150   -8.7%    **1.10x (?)**
SubstringEqualString                  171    159    -7.0%    **1.08x (?)**
StringSwitch                          289    270    -6.6%    **1.07x (?)**

------- Code size: -Osize -------

------- Performance (x86_64): -Onone -------

REGRESSION                            OLD    NEW    DELTA    RATIO
Ackermann                             6024   7166   +19.0%   **0.84x (?)**
IterateData                           2210   2461   +11.4%   **0.90x (?)**

IMPROVEMENT                           OLD    NEW    DELTA    RATIO
Breadcrumbs.MutatedUTF16ToIdx.Mixed   220    189    -14.1%   **1.16x**
Breadcrumbs.MutatedIdxToUTF16.Mixed   232    201    -13.4%   **1.15x**
BinaryFloatingPointPropertiesNextUp   134    122    -9.0%    **1.10x (?)**
ArrayAppendReserved                   4330   3960   -8.5%    **1.09x (?)**
ObjectiveCBridgeStubDateMutation      824    758    -8.0%    **1.09x (?)**
BinaryFloatingPointPropertiesUlp      131    122    -6.9%    **1.07x (?)**

------- Code size: -swiftlibs -------

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I think this is fine. I just want to point out the trade-offs being made.

  1. Recombining destroy_addr + copy_addr makes the pass non-repeatable. Ideally, a pass will be repeatable (isotropic?). If I run a pass. Then recompute all the analyses invalidated by the pass. Then I run the pass again. The second time around, no analyses should be invalidated. Also, memory allocation for instructions won't grow endlessly. It's probably fine in this case though for a pass that only runs a few times.

  2. Not recombining destroy_addr + copy_addr results in extra runtime calls and might defeat some other analysis. I'm much more concerned the extra runtime calls.

So, this seems like the right approach. If we wanted to avoid recombining and make the split form canonical, then I think we would need a non-OSSA pass to do that just before IRGen.

/cc @eeckstein

@nate-chandler nate-chandler marked this pull request as ready for review February 22, 2022 17:27
@nate-chandler nate-chandler merged commit e35261f into swiftlang:main Feb 22, 2022
@nate-chandler nate-chandler deleted the lexical_lifetimes/lexical_destroy_addr_hoisting/split-copy_addr branch February 22, 2022 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants