This is an archive of the discontinued LLVM Phabricator instance.

[X86] Simplify __cpuid_count
Needs ReviewPublic

Authored by MaskRay on Jun 23 2022, 1:52 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Use the x86-32 implementation for x86-64, i.e. replace =r plus xchgq with =b.
Using =r seems like a workaround when RBX as a base register did not
work well =b (2014-09 416efb5f909e45f67ee81d382a708fc41666c5c6), likely
no longer relevant today.

Diff Detail

Event Timeline

MaskRay created this revision.Jun 23 2022, 1:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2022, 1:52 PM
MaskRay requested review of this revision.Jun 23 2022, 1:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2022, 1:52 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I think it's still relevant. We had the same issue on Windows as recently as https://github.com/llvm/llvm-project/issues/49477 see also https://github.com/llvm/llvm-project/issues/17204

MaskRay added a comment.EditedJun 23 2022, 2:04 PM

Ah, OK. I am investigating a miscompile that : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \ may assign "=r" to use RDX. The output then looks like

xchgq %rbx, %rdx
cpuid
xchgq %rbx, %rdx

and rbx is clobbered, since cpuid writes rax/rbx/rcx/rdx.

This patch can work around the bug.