This is an archive of the discontinued LLVM Phabricator instance.

Fix X86-64 ABIT issue when splitting an i128 into two i64 during function call
Needs RevisionPublic

Authored by serge-sans-paille on Aug 12 2021, 8:09 AM.

Details

Summary

X86-64 ABI mandates that wrt. argument passing, i128 is considered as a struct {i64, i64}
and thus that it cannot be split across register and stack.

GCC already implements this behavior, while clang doesn't, which can cause
subtle runtime issues when mixing both object files.

As a side effect, share some code between 32 and 64 bit implementation.

Diff Detail

Event Timeline

serge-sans-paille requested review of this revision.Aug 12 2021, 8:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2021, 8:09 AM

This diff relies on the ArgumentNeedsConsecutiveRegisters property which is unused for X86. I'm new to codegen and will happily follow another track.

pengfei requested changes to this revision.Sep 14 2021, 6:48 PM
pengfei added inline comments.
llvm/lib/Target/X86/X86CallingConv.td
545

This is not correct. See the generated code in large-argument-count-i128.ll:12. We want the i128 (consecutive 2 i64) memory is 16 byte aligned instead of 2 i64 that aligned 16 bytes.

llvm/test/CodeGen/X86/large-argument-count-i128.ll
12

This should be 8?

This revision now requires changes to proceed.Sep 14 2021, 6:48 PM