Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

Improve fregs-graph.
I'm creating this as a way to keep track of shortcomings of the current implementation. Some of these are directly taken from TODOS, other are my own opinions. # Things that could be looked at. ## Compress spill slots. Currently we assign each vreg a fixed spill slot. This is terrible for cache performance. It's possible to end up with sequences like this: ```asm block_ca01_info: _ca01: movq 16(%rbp),%r14 movq 24(%rbp),%rax movq %rax,144(%rsp) movq 32(%rbp),%rsi movq 40(%rbp),%rdi movq 64(%rbp),%rbx movq 56(%rbp),%rax movq %rax,208(%rsp) movq 48(%rbp),%rax movq %rax,168(%rsp) movq 8(%rbp),%rax movq %rax,216(%rsp) addq $8,%rbp ``` Which splits spill slots over multiple cache lines increasing cache pressure. Things possibly worth trying: - Assign spill slots in the order they appear - hopefully reducing the average spread within code blocks. - Dynamically assign vregs to spill slots. For the later if we have large independent subgraphs we will sometimes get away with using far fewer slots. The reason simply being that non overlapping vregs can share spill slots. Doing this in an efficient manner however isn't easy. ## We sometimes load + spill vregs when we could use memory addressing. One example I've seen a few times in nofib is this: ``` movq 208(%rsp),%rax incq %rax movq %rax,208(%rsp) ``` Which we should replace with a single `inc` operating on memory. ## Lift the stack size limit. There is already a patch [in flight](https://gitlab.haskell.org/ghc/ghc/merge_requests/219). ## Revisit spill costs. Currently the allocator always spills the longest live range. Which often works but is certainly not a great metric. Ideas: ### Consider loop membership. At least for x86/64 this would be easy to achieve on basic block granularity using the CFG that is also used for block layout. ### Revisit chaitins cost model. There have been major changes to cpus (amd64 becoming the norm) and the backend so at a minimum this cost model should be reevaluated. ## Try splitting long live ranges instead of simply spilling the complete live range. After all long live ranges were the original reason to switch to a life range only based cost heuristic. ## Use a different spill algorithm altogether. Maybe Chows live range splitting based approach would be an option. See "The priority based coloring approach to register allocation" for details. <details><summary>Trac metadata</summary> | Trac field | Value | | ---------------------- | ------------------ | | Version | 8.6.3 | | Type | Task | | TypeOfFailure | OtherFailure | | Priority | normal | | Resolution | Unresolved | | Component | Compiler (CodeGen) | | Test case | | | Differential revisions | | | BlockedBy | | | Related | | | Blocking | | | CC | | | Operating system | | | Architecture | | </details> <!-- {"blocked_by":[],"summary":"Improve fregs-graph.","status":"New","operating_system":"","component":"Compiler (CodeGen)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":["fregs-graph"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Task","description":"I'm creating this as a way to keep track of shortcomings of the current implementation.\r\n\r\nSome of these are directly taken from TODOS, other are my own opinions.\r\n\r\n= Things that could be looked at.\r\n\r\n== Compress spill slots.\r\n\r\nCurrently we assign each vreg a fixed spill slot. This is terrible for cache performance.\r\n\r\nIt's possible to end up with sequences like this:\r\n\r\n{{{#!asm\r\nblock_ca01_info:\r\n_ca01:\r\n\tmovq 16(%rbp),%r14\r\n\tmovq 24(%rbp),%rax\r\n\tmovq %rax,144(%rsp)\r\n\tmovq 32(%rbp),%rsi\r\n\tmovq 40(%rbp),%rdi\r\n\tmovq 64(%rbp),%rbx\r\n\tmovq 56(%rbp),%rax\r\n\tmovq %rax,208(%rsp)\r\n\tmovq 48(%rbp),%rax\r\n\tmovq %rax,168(%rsp)\r\n\tmovq 8(%rbp),%rax\r\n\tmovq %rax,216(%rsp)\r\n\taddq $8,%rbp\r\n}}}\r\n\r\nWhich splits spill slots over multiple cache lines increasing cache pressure.\r\n\r\nThings possibly worth trying:\r\n\r\n* Assign spill slots in the order they appear - hopefully reducing the average spread within code blocks.\r\n* Dynamically assign vregs to spill slots.\r\n\r\nFor the later if we have large independent subgraphs we will sometimes get away with using far fewer slots. \r\nThe reason simply being that non overlapping vregs can share spill slots.\r\n\r\nDoing this in an efficient manner however isn't easy.\r\n\r\n== We sometimes load + spill vregs when we could use memory addressing.\r\n\r\nOne example I've seen a few times in nofib is this:\r\n{{{\r\n\tmovq 208(%rsp),%rax\r\n\tincq %rax\r\n\tmovq %rax,208(%rsp)\r\n}}}\r\n\r\nWhich we should replace with a single `inc` operating on memory.\r\n\r\n== Lift the stack size limit.\r\n\r\nThere is already a patch [https://gitlab.haskell.org/ghc/ghc/merge_requests/219 in flight].\r\n\r\n== Revisit spill costs.\r\n\r\nCurrently the allocator always spills the longest live range. Which often works but is certainly not a great metric.\r\n\r\nIdeas:\r\n\r\n=== Consider loop membership.\r\n\r\nAt least for x86/64 this would be easy to achieve on basic block granularity using the CFG that is also used for block layout.\r\n\r\n=== Revisit chaitins cost model.\r\n\r\nThere have been major changes to cpus (amd64 becoming the norm) and the backend\r\nso at a minimum this cost model should be reevaluated.\r\n\r\n== Try splitting long live ranges instead of simply spilling the complete live range.\r\n\r\nAfter all long live ranges were the original reason to switch to a life range only based cost heuristic.\r\n\r\n== Use a different spill algorithm altogether.\r\n\r\nMaybe Chows live range splitting based approach would be an option.\r\nSee \"The priority based coloring approach to register allocation\" for details.\r\n\r\n\r\n\r\n\r\n","type_of_failure":"OtherFailure","blocking":[]} -->
issue