Skip to content

TempRValueOpt: extend access scopes #36540

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

Merged
merged 1 commit into from
Mar 23, 2021

Conversation

eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Mar 22, 2021

Try to move an end_access down to extend the access scope over all uses of the temporary.
For example:

   %a = begin_access %src
   copy_addr %a to [initialization] %temp : $*T
   end_access %a
   use %temp

We must not replace %temp with %a after the end_access. Instead we try to move the end_access after use %temp.

This fixes generation of invalid SIL and/or the invalid removal of access checks.

The change also contains some small non-functional re-factorings/improvements.

@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

@eeckstein eeckstein requested a review from atrick March 22, 2021 18:55
@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
FlattenListFlatMap 4891 5644 +15.4% 0.87x (?)
 
Improvement OLD NEW DELTA RATIO
DictionaryKeysContainsCocoa 29 27 -6.9% 1.07x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
DictionaryKeysContainsNative 26 29 +11.5% 0.90x (?)

Code size: -Osize

Performance: -Onone

Code size: -swiftlibs

How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 12-Core Intel Xeon E5
  Processor Speed: 2.7 GHz
  Number of Processors: 1
  Total Number of Cores: 12
  L2 Cache (per Core): 256 KB
  L3 Cache: 30 MB
  Memory: 64 GB

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - bafc128336c532ccd39b2d9204da3d38899a6e39

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - bafc128336c532ccd39b2d9204da3d38899a6e39

Try to move an end_access down to extend the access scope over all uses of the temporary.
For example:

   %a = begin_access %src
   copy_addr %a to [initialization] %temp : $*T
   end_access %a
   use %temp

We must not replace %temp with %a after the end_access. Instead we try to move the end_access after "use %temp".

This fixes generation of invalid SIL and/or the invalid removal of access checks.
@eeckstein eeckstein force-pushed the fix-temp-rvalue-opt branch from bafc128 to 7c454e3 Compare March 22, 2021 20:55
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Performance: -O

Improvement OLD NEW DELTA RATIO
FlattenListFlatMap 6048 4049 -33.1% 1.49x (?)
DataAppendDataSmallToSmall 4660 4240 -9.0% 1.10x (?)
NSStringConversion.MutableCopy.Medium 876 817 -6.7% 1.07x (?)
NSStringConversion.UTF8 992 926 -6.7% 1.07x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
String.data.LargeUnicode 110 126 +14.5% 0.87x (?)
String.data.Medium 111 124 +11.7% 0.90x (?)

Code size: -Osize

Performance: -Onone

Improvement OLD NEW DELTA RATIO
String.data.LargeUnicode 209 193 -7.7% 1.08x (?)

Code size: -swiftlibs

How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 12-Core Intel Xeon E5
  Processor Speed: 2.7 GHz
  Number of Processors: 1
  Total Number of Cores: 12
  L2 Cache (per Core): 256 KB
  L3 Cache: 30 MB
  Memory: 64 GB

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 7c454e3

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.

That looks safe enough. Thanks!

@eeckstein
Copy link
Contributor Author

@swift-ci smoke test linux

@eeckstein eeckstein merged commit 126850e into swiftlang:main Mar 23, 2021
@eeckstein eeckstein deleted the fix-temp-rvalue-opt branch March 23, 2021 09:50
} else if (endAccessToMove) {
// We cannot move an end_access over a begin_access. This would destroy
// the proper nesting of accesses.
if (isa<BeginAccessInst>(&inst))
Copy link
Contributor

@atrick atrick Mar 23, 2021

Choose a reason for hiding this comment

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

@eeckstein We also still have an "unpaired" begin access, so strictly speaking, finding all the access scope beginnings means doing this:
isa<BeginAccessInst>(inst) || isa<BeginUnpairedAccessInst>(inst)
I'm surprised there's no helper for it yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The begin_unpaired_access is only used in the KeyPath runtime functions. And we compile the stdlib without access enforcement. So it should not be a problem.
But checking for the unpaired access does not harm. I'll add it.

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.

3 participants