Skip to content

IRGen: don't create ObjC methods with the unnamed_addr attribute #29188

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
Jan 15, 2020

Conversation

eeckstein
Copy link
Contributor

In some places, Foundation is comparing ObjC method pointers.
Therefore LLVM's function merging pass must not create aliases for identica; functions, but instead create thunks.
This can be ensured by not creating ObjC methods with the unnamed_addr attribute.

rdar://problem/58483698

@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
EqualSubstringSubstring 21 28 +33.3% 0.75x (?)
EqualSubstringSubstringGenericEquatable 21 28 +33.3% 0.75x (?)
EqualSubstringString 21 28 +33.3% 0.75x (?)
LessSubstringSubstringGenericComparable 21 28 +33.3% 0.75x (?)
LessSubstringSubstring 21 27 +28.6% 0.78x
EqualStringSubstring 22 28 +27.3% 0.79x (?)
NSStringConversion.Long 523 608 +16.3% 0.86x (?)
StringComparison_longSharedPrefix 320 356 +11.2% 0.90x (?)
NSStringConversion.Medium 252 272 +7.9% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
UTF8Decode_InitDecoding 124 106 -14.5% 1.17x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
LessSubstringSubstring 21 27 +28.6% 0.78x
EqualSubstringString 21 27 +28.6% 0.78x
LessSubstringSubstringGenericComparable 21 27 +28.6% 0.78x
EqualSubstringSubstring 22 28 +27.3% 0.79x (?)
EqualStringSubstring 22 28 +27.3% 0.79x (?)
EqualSubstringSubstringGenericEquatable 22 28 +27.3% 0.79x (?)
SuffixCountableRange 4 5 +25.0% 0.80x (?)
NSStringConversion.Long 493 570 +15.6% 0.86x
StringComparison_longSharedPrefix 317 351 +10.7% 0.90x (?)
IterateData 869 954 +9.8% 0.91x (?)
NSStringConversion.Medium 236 255 +8.1% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
UTF8Decode_InitDecoding 126 104 -17.5% 1.21x
ObjectiveCBridgeStringHash 43 40 -7.0% 1.07x (?)

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
EqualSubstringSubstringGenericEquatable 25 31 +24.0% 0.81x
LessSubstringSubstringGenericComparable 25 31 +24.0% 0.81x
EqualSubstringSubstring 26 32 +23.1% 0.81x
LessSubstringSubstring 26 32 +23.1% 0.81x (?)
EqualStringSubstring 26 32 +23.1% 0.81x (?)
EqualSubstringString 26 32 +23.1% 0.81x
ArrayOfGenericPOD2 714 836 +17.1% 0.85x (?)
 
Improvement OLD NEW DELTA RATIO
UTF8Decode_InitDecoding 143 124 -13.3% 1.15x (?)
ObjectiveCBridgeStringHash 43 40 -7.0% 1.07x (?)
DataSubscriptMedium 58 54 -6.9% 1.07x (?)

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 mini
  Model Identifier: Macmini8,1
  Processor Name: Intel Core i7
  Processor Speed: 3.2 GHz
  Number of Processors: 1
  Total Number of Cores: 6
  L2 Cache (per Core): 256 KB
  L3 Cache: 12 MB
  Memory: 64 GB

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 4fc55830bcd4d4a8f86151d1176f90b9bcbe81e1

@eeckstein
Copy link
Contributor Author

@swift-ci test macOS

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci test macOS

Copy link
Contributor

@aschwaighofer aschwaighofer left a comment

Choose a reason for hiding this comment

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

Maybe in a follow-up can you add a comment reminding us in the future to not do this again?

@@ -130,57 +130,57 @@ var NSS : NSString = NSString()

// -- NSString methods don't convert 'self'
extension NSString {
// CHECK: define internal [[OPAQUE:.*]]* @"$sSo8NSStringC11objc_bridgeE13nsstrFakePropABvgTo"([[OPAQUE:.*]]*, i8*) unnamed_addr
// CHECK: define internal void @"$sSo8NSStringC11objc_bridgeE13nsstrFakePropABvsTo"([[OPAQUE:.*]]*, i8*, [[OPAQUE:.*]]*) unnamed_addr
// CHECK: define internal [[OPAQUE:.*]]* @"$sSo8NSStringC11objc_bridgeE13nsstrFakePropABvgTo"([[OPAQUE:.*]]*, i8*)
Copy link
Member

Choose a reason for hiding this comment

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

Could you add:

CHECK-SAME-NOT: unnamed_addr

here and the other locations where it was removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll add a regexp at the end of the line so that unnamed_addr is not matched.

@jckarter
Copy link
Contributor

This seems like an unfortunate blanket policy. Do we know what Foundation is using the imp pointers for? Is it for an isolated enough set of cases that we could special case them instead of eliminating this optimization for all ObjC entry points?

In some places, Foundation is comparing ObjC method pointers.
Therefore LLVM's function merging pass must not create aliases for identica; functions, but instead create thunks.
This can be ensured by not creating ObjC methods with the unnamed_addr attribute.

rdar://problem/58483698
@eeckstein
Copy link
Contributor Author

@jckarter It's used in Foundation to check if a method has an override. I'm not sure if there are more cases. Anyway, I think we doesn't harm to be on the safe side here. I don't think this attribute has a significant performance/code-size effect (for objc methods).

@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@eeckstein eeckstein merged commit f980105 into swiftlang:master Jan 15, 2020
@eeckstein eeckstein deleted the fix-unnamed-addr branch January 15, 2020 06:31
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.

5 participants