Skip to content
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

[SR-6329] [code size] IRGen's splitting into several LLVM modules (num-threads > 0) inhibits redundant code elimination #48879

Open
aschwaighofer opened this issue Nov 8, 2017 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself IRGen LLVM IR generation

Comments

@aschwaighofer
Copy link
Member

Previous ID SR-6329
Radar rdar://problem/35282001
Original Reporter @aschwaighofer
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, IRGen
Assignee None
Priority Medium

md5: 780a2f361672efbe0a10442744350e1f

Issue Description:

When we run the swift compiler in multithreaded compilation (-Xfrontend -num-threads -Xfrontend 1..n) mode we split up a swift module into several LLVM modules (one per source file). We put a definition into a LLVM module based on the swift source file the definition stemmed from.

This split can inhibit LLVM passes that reduce code size based on global defintion visibility e.g. the merge functions pass.

Experiments have shown that we loose (significant) code size reducing opportunity because of this.

We don't want to give up on multi-threaded compilation so we should investigate how to get back most of this code size saving opportunity we loose this way.

We should look into better partioning into LLVM modules:

  • be cleverer where we put definitions e.g.

  • emit all value witnesses, thunks, etc. into the same LLVM module

  • emit all specializations of stdlib functions into the same LLVM modules (if we don't do so already)

  • introduce a reasonable maximum number of LLVM modules

Experiment running the swift source compatibility suite with -num-threads 0 to illustrate what we win with disabling num-threads:

Project/platform                           :        Old        New   Percent
                                                                          
Alamofire/iphoneos/arm64                   :     545940     536198    1.78
Alamofire/iphoneos/armv7                   :     568043     561244    1.20
iOS Example/iOS/arm64                      :      68804      68655    0.22
iOS Example/iOS/armv7                      :      68766      68807   -0.06
Alamofire/iphoneos                         :    1113983    1097442    1.48
Alamofire/iphoneos                         :    1113983    1097442    1.48
iOS Example/iphoneos                       :     137570     137462    0.08
AMScrollingNavbar/iphoneos/arm64           :      63916      62834    1.69
AMScrollingNavbar/iphoneos/armv7           :      63478      62868    0.96
AMScrollingNavbar/iphoneos                 :     127394     125702    1.33
Socket/iphoneos/arm64                      :     107893     107305    0.54
Socket/iphoneos/armv7                      :     122081     121525    0.46
Socket/iphoneos                            :     229974     228830    0.50           
ChattoApp/iphoneos/arm64                   :     169377     162517    4.05
ChattoApp/iphoneos/armv7                   :     175738     170081    3.22                                                                                                                                                                                                
Chatto/iphoneos/arm64                      :     278230     266871    4.08                       
Chatto/iphoneos/armv7                      :     289331     278818    3.63           
ChattoAdditions/iphoneos/arm64             :     635153     593541    6.55             
ChattoAdditions/iphoneos/armv7             :     651410     615575    5.50            
Chatto/iphoneos                            :     567561     545689    3.85               
ChattoAdditions/iphoneos                   :    1286563    1209116    6.02         
ChattoApp/iphoneos                         :     345115     332598    3.63       
Chatto/iphoneos                            :     567561     545689    3.85         
ChattoAdditions/iphoneos                   :    1286563    1209116    6.02               
CleanroomLogger/watchos                    :     193947     186325    3.93       
Dollar/macos                               :     188580     188580    0.00
Dwifft/iphoneos/arm64                      :     106753     106056    0.65
Dwifft/iphoneos/armv7                      :     114598     114229    0.32
Dwifft/iphoneos                            :     221351     220285    0.48
IBAnimatable/iphoneos/arm64                :    1818465    1739753    4.33
IBAnimatable/iphoneos/armv7                :    1865133    1824740    2.17
IBAnimatableApp/iphoneos/arm64             :     210715     189801    9.93
IBAnimatableApp/iphoneos/armv7             :     214911     201432    6.27
IBAnimatable/iphoneos                      :    3683598    3564493    3.23
IBAnimatable/iphoneos                      :    3683598    3564493    3.23
IBAnimatableApp/iphoneos                   :     425626     391233    8.08
JSQCoreDataKit/iphoneos/arm64              :      81514      79257    2.77
JSQCoreDataKit/iphoneos/armv7              :      84904      82883    2.38
JSQCoreDataKit/iphoneos                    :     166418     162140    2.57
JSQDataSourcesKit/iphoneos/arm64           :     106721     104351    2.22
JSQDataSourcesKit/iphoneos/armv7           :     103856     102613    1.20
JSQDataSourcesKit/iphoneos                 :     210577     206964    1.72
KeychainAccess/watchos                     :     203676     203676    0.00
Prelude/appletvos                          :     115514     112449    2.65
Prelude_UIKit/appletvos                    :     256090     228096   10.93
ReactiveExtensions/appletvos               :     179842     165094    8.20
ReactiveSwift/appletvos                    :     820886     797139    2.89
Result/appletvos                           :      61954      61515    0.71
Kingfisher/watchos                         :     271030     266049    1.84
Kommander/watchos                          :      67872      68519   -0.95
LaunchScreenSnapshot/iphoneos/arm64        :      45356      45356    0.00
LaunchScreenSnapshot/iphoneos/armv7        :      45480      45480    0.00           
LaunchScreenSnapshot/iphoneos              :      90836      90836    0.00
ObjectMapper/watchos                       :     242167     250902   -3.61
Example/iphoneos/arm64                     :      30022      29820    0.67
Example/iphoneos/armv7                     :      27219      27167    0.19
PanelKit/iphoneos/arm64                    :     143162     137770    3.77
PanelKit/iphoneos/armv7                    :     150434     144865    3.70
Example/iphoneos                           :      57241      56987    0.44
PanelKit/iphoneos                          :     293596     282635    3.73
PanelKit/iphoneos                          :     293596     282635    3.73
PromiseKit/appletvos                       :     264628     265513   -0.33
ReLax/appletvos                            :     159652     155603    2.54
ReactiveCocoa/watchos                      :      91960      89306    2.89
ReactiveSwift/watchos                      :     719314     726377   -0.98
Result/watchos                             :      49945      49721    0.45
ReactiveSwift/watchos                      :     719202     726265   -0.98
Result/watchos                             :      49945      49721    0.45
Realm/watchos                              :    3118605    3118605    0.00
ReSwift/watchos                            :      48641      48009    1.30           
RxCocoa/iphoneos/arm64                     :     529820     529820    0.00     
RxCocoa/iphoneos/armv7                     :     489203     489203    0.00  
RxSwift/iphoneos/arm64                     :     909924     909924    0.00
RxSwift/iphoneos/armv7                     :     861450     861450    0.00
RxCocoa/iphoneos                           :    1019023    1019023    0.00
RxSwift/iphoneos                           :    1771374    1771374    0.00
RxSwift/appletvos                          :    1099264    1050965    4.39
RxTest/appletvos                           :      80039      79430    0.76
Siesta/macos                               :     611178     602905    1.35
SiestaUI/macos                             :         48         48    0.00
Starscream/appletvos                       :     131025     130916    0.08
SwiftDate/watchos                          :     321833     324597   -0.86
SwifterSwift/watchos                       :     416216     400671    3.73
                                                                          
Total                                      :   40923954   39931989    2.42
@belkadan
Copy link
Contributor

belkadan commented Nov 8, 2017

Note: No need for -Xfrontend here; the driver accepts -num-threads directly.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself IRGen LLVM IR generation
Projects
None yet
Development

No branches or pull requests

2 participants