Title: gh-129987: Disable GCC SLP autovectorization for the interpreter loop on x86-64 by mpage · Pull Request #132295 · python/cpython · GitHub
Open Graph Title: gh-129987: Disable GCC SLP autovectorization for the interpreter loop on x86-64 by mpage · Pull Request #132295 · python/cpython
X Title: gh-129987: Disable GCC SLP autovectorization for the interpreter loop on x86-64 by mpage · Pull Request #132295 · python/cpython
Description: #131750 mysteriously caused a ~6% regression for the free-threaded build. The cause was poor code generation of opcode dispatch in the interpreter loop. Before the change the dispatch code looked like:
/root/src/cpython/Python/generated_cases.c.h:8808 [LOAD_FAST_BORROW]
DISPATCH();
19cd0a: mov -0x268(%rbp),%rsi
19cd11: movzbl %ah,�x
19cd14: movzbl %al,�x
19cd17: mov �x,%r10d
19cd1a: jmp *(%rsi,%rax,8)
After the change, the dispatch code looked like:
# Shared dispatch code
/root/src/cpython/Python/generated_cases.c.h:81 [BINARY_OP]
DISPATCH();
19dd67: mov -0x280(%rbp),%r10
19dd6e: movzbl %ah,�x
19dd71: movzbl %al,�x
19dd74: mov �x,%r14d
19dd77: mov -0x270(%rbp),%rcx
19dd7e: mov (%rcx,%rax,8),%rdx
19dd82: nopw 0x0(%rax,%rax,1)
19dd88: movq -0x258(%rbp),%xmm0
19dd90: movq %r12,%xmm4
19dd95: punpcklqdq %xmm4,%xmm0
19dd99: movhlps %xmm0,%xmm3
19dd9c: movq %xmm0,%r15
19dda1: movq %xmm3,%r11
19dda6: mov %r11,%rcx
19dda9: jmp *%rdx
# Duplicated dispatch code
/root/src/cpython/Python/generated_cases.c.h:8808 [LOAD_FAST_BORROW]
DISPATCH();
19dde4: movzbl %ah,�x
19dde7: movzbl %al,�x
19ddea: mov �x,%r14d
19dded: mov -0x270(%rbp),%rcx
19ddf4: mov (%rcx,%rax,8),%rdx
19ddf8: jmp 19dd99 <_PyEval_EvalFrameDefault+0x289>
There are two problems:
We now have two jumps (one direct jump to the shared dispatch logic and one indirect jump to the next opcode handler) instead of one (the indirect jump to the opcode handler).
There's a significant amount of register shuffling in the shared dispatch code.
Both of these problems appear to be caused by GCC's SLP autovectorizer. After the change, it decides to store both the next_instr pointer and the stack_pointer in a single 128 bit register in the shared basic block that contains the opcode dispatch. This is introduced in the slp1 pass (tree dump below):
_24061 = VIEW_CONVERT_EXPR
Open Graph Description: #131750 mysteriously caused a ~6% regression for the free-threaded build. The cause was poor code generation of opcode dispatch in the interpreter loop. Before the change the dispatch code looked l...
X Description: #131750 mysteriously caused a ~6% regression for the free-threaded build. The cause was poor code generation of opcode dispatch in the interpreter loop. Before the change the dispatch code looked l...
Opengraph URL: https://github.com/python/cpython/pull/132295
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:d6ade225-68bd-90fc-c61b-fa6b91e59b27 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8134:38E318:3D80305:4DB093A:6B0241E2 |
| html-safe-nonce | 082b54054ca547633c11452319b2ae9f4b987f644887ab11df209946ec49c095 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTM0OjM4RTMxODozRDgwMzA1OjREQjA5M0E6NkIwMjQxRTIiLCJ2aXNpdG9yX2lkIjoiMTUzOTU4NDIxNjg5OTQyNDk4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4d4523da4dd375a8846d7a536bae08fee8cb3be74bc4aaa10455ec6cff48ba41 |
| hovercard-subject-tag | pull_request:2447154180 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/132295/files |
| twitter:image | https://avatars.githubusercontent.com/u/577841?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/577841?s=400&v=4 |
| og:image:alt | #131750 mysteriously caused a ~6% regression for the free-threaded build. The cause was poor code generation of opcode dispatch in the interpreter loop. Before the change the dispatch code looked l... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width