This is an archive of the discontinued LLVM Phabricator instance.

[X86][fastcall][vectorcall] Move capability check before free register update
ClosedPublic

Authored by pengfei on Sep 15 2022, 12:54 AM.

Details

Summary

When passing arguments with __fastcall or __vectorcall in 32-bit MSVC, the following arguments have chance to be passed by register if the current one failed. __regcall from ICC is on the contrary: https://godbolt.org/z/4MPbzhaMG
All the three calling conversions are not supported in GCC.

Fixes: #57737

Diff Detail

Event Timeline

pengfei created this revision.Sep 15 2022, 12:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2022, 12:54 AM
pengfei requested review of this revision.Sep 15 2022, 12:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2022, 12:54 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
hans added a subscriber: hans.Sep 15 2022, 10:28 AM

Instead of just referring to the bug in the commit message, can you add some text explaining the effects of this change, e.g. on the __fastcall void f(unsigned long long a, int b, int c) function in the bug and that this matches MSVC?

Did you double check whether this matches GCC too?

Please also add a release note about this since it affects the ABI.

clang/test/CodeGen/mangle-windows.c
50

Should we add tests to cover the vectorcall and regcall cases too?

rnk added inline comments.Sep 15 2022, 11:47 AM
clang/lib/CodeGen/TargetInfo.cpp
1780

I think we could improve readability here with some named variable booleans and by avoiding the lambda. These come to mind:

bool IsPtrOrInt =
bool CCUsesInReg = ...
pengfei updated this revision to Diff 460991.Sep 17 2022, 4:49 AM
pengfei marked 2 inline comments as done.

Address review comments.

pengfei retitled this revision from [X86][fastcall] Move capability check before free register update to [X86][fastcall][vectorcall] Move capability check before free register update.Sep 17 2022, 5:03 AM
pengfei edited the summary of this revision. (Show Details)
pengfei edited the summary of this revision. (Show Details)
rnk added a comment.Sep 17 2022, 11:16 AM

Thanks, I have more comments, sorry I didn't add them on the first review.

clang/lib/CodeGen/TargetInfo.cpp
1782–1783

I see, no intended behavior change for regcall.

1785–1789

Seems like this can be simplified to:

// Return true to apply inreg to all legal parameters except on for MCU targets.
return !IsMCUABI;
clang/test/CodeGen/mangle-windows.c
50

This file is intended to test the C mangling. Most of the other tests don't look at the IR prototype. I think a better home for both tests is:
../clang/test/CodeGen/stdcall-fastcall.c
../clang/test/CodeGen/vectorcall.c

Do we already have coverage for this case for regcall? Please ensure we have coverage or add it.

pengfei updated this revision to Diff 461071.Sep 18 2022, 7:09 AM

Address review comments. Thanks @rnk!

pengfei marked 2 inline comments as done.Sep 18 2022, 7:09 AM
pengfei updated this revision to Diff 461072.Sep 18 2022, 7:11 AM

Missing a !.

rnk accepted this revision.Sep 19 2022, 9:22 AM

lgtm, thanks for the fix!

This revision is now accepted and ready to land.Sep 19 2022, 9:22 AM