Skip to content

[Windows] Enable tailcall VM on Windows with clang-cl#21619

Open
henderkes wants to merge 5 commits intophp:masterfrom
henderkes:feat/clang-windows-tailcall
Open

[Windows] Enable tailcall VM on Windows with clang-cl#21619
henderkes wants to merge 5 commits intophp:masterfrom
henderkes:feat/clang-windows-tailcall

Conversation

@henderkes
Copy link
Copy Markdown
Contributor

@henderkes henderkes commented Apr 3, 2026

requires #21618 first

Build PHPBench no-JIT PHPBench JIT FrankenPHP RPS
MSVC Release 450K 770K 200
Clang Master 330K 550K 170
Clang TAILCALL VM 880K (+96% vs MSVC, +167% vs Clang) 1.3M (+69% vs MSVC, +136% vs Clang) 334 (+67% vs MSVC, +96% vs Clang)

cc @php/windows-team any chance the official releases will be switched to clang? compiles a bit longer, but performance is improved vastly

@henderkes
Copy link
Copy Markdown
Contributor Author

@arnaud-lb since this requires the fixes to clang in the first place, perhaps it's better I just mark this PR as ready for review and close the other one?

@arnaud-lb
Copy link
Copy Markdown
Member

I would prefer if the other PR was merged first, then this one rebased so it contains only changes related to tailcall VM.

@shivammathur
Copy link
Copy Markdown
Member

cc @php/windows-team any chance the official releases will be switched to clang? compiles a bit longer, but performance is improved vastly

Probably not in the near term. Moving all dependencies and the Windows build toolchain over to clang is not trivial, and I’d like to first see how far we can get with improved MSVC PGO and possibly [[msvc::musttail]] before considering a compiler switch.

@henderkes
Copy link
Copy Markdown
Contributor Author

henderkes commented Apr 3, 2026

cc @php/windows-team any chance the official releases will be switched to clang? compiles a bit longer, but performance is improved vastly

Probably not in the near term. Moving all dependencies and the Windows build toolchain over to clang is not trivial

The dependencies can keep being compiled with MSVC perfectly fine (assuming you mean libraries). Clang has no issue using them. The full snapshot build succeeds for clang, so I think this only affects unbundled extensions from pie/pecl.

and I’d like to first see how far we can get with improved MSVC PGO and possibly [[msvc::musttail]] before considering a compiler switch.

Not very far. [[msvc::musttail]] is C++ only while __preserve_none is C only. __preserve_none did offer a 5-8% performance uplift for the CALL VM too (see: #21563). Other than that, --disable-security-flags helps MSVC performance (450k -> 620k, jit unchanged), but it doesn't get anywhere near Clang with the tailcall VM.

As for PGO; it generally didn't make a huge difference. I added a frankenphp case for the symfony demo and the uplift was just 10%, still 33% slower than Clang without PGO. It unsurprisingly helped the phpbench case a lot, but that barely improves what I was doing this whole thing for.

Comment thread .github/workflows/test-suite.yml Outdated
@henderkes henderkes force-pushed the feat/clang-windows-tailcall branch from 68e7d8a to aa36e75 Compare April 21, 2026 07:49
@henderkes henderkes marked this pull request as ready for review April 21, 2026 07:58
@henderkes henderkes requested a review from dstogov as a code owner April 21, 2026 07:58
@henderkes henderkes requested a review from iluuu1994 April 21, 2026 07:58
@henderkes
Copy link
Copy Markdown
Contributor Author

@iluuu1994 @arnaud-lb rebased for the current master branch, only left with a small changelist now

Comment thread win32/build/confutils.js
var vc_ver = probe_binary(PATH_PROG('cl', null));
ADD_FLAG("CFLAGS"," -fms-compatibility -fms-compatibility-version=" + vc_ver + " -fms-extensions");

if (CLANGVERS >= 1900 && (TARGET_ARCH === 'x64' || TARGET_ARCH === 'arm64')) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't have an ARM64 windows pc to test this with, neither does the CI. Should I perhaps limit this to x64 only as a defensive check for now? We only do x64 releases at FrankenPHP anyhow.

I know clang can do tailcalls on arm64, but I'm not sure if the jit changes work for it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe @shivammathur is able to test on arm64?

Otherwise it would be fine to limit this to x64 until someone can test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, that would be great. Could you add the CI: All variations tag please so that the Clang compilation actually runs?

Perhaps we should also add a test to make sure clang on windows actually produces a php binary with ZEND_VM_KIND = tailcall vm?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh yeah, that would be great. Could you add the CI: All variations tag please so that the Clang compilation actually runs?

Done, you can push again to retrigger CI.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@henderkes There is a windows-11-arm runner you can use to test this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants