Skip to content

Conversation

@konstantinschwarz
Copy link
Collaborator

In AIEs default calling convention, all vector registers are caller saved. However, most compiler-rt builtin library functions do not use vector registers. To avoid having to spill vectors to memory in the caller function, we can attach a different calling convention to these library functions.

I manually inspected each library function where we apply the alternative calling convention to make sure none of them actually use vector registers. To make this actually save and robust, we should also add a custom calling convention attribute to the frontend that ensures vector registers are actually saved by the callee.

@konstantinschwarz
Copy link
Collaborator Author

This saves up to 512 bytes of stack (ArgMin/ArgMax), and some very minor code size savings.

Core_PMSize_absolute Core_StackSize_absolute

setLibcallCallingConv(RTLIB::SREM_I32, CallingConv::AIE_PreserveAll_Vec);
setLibcallCallingConv(RTLIB::SREM_I64, CallingConv::AIE_PreserveAll_Vec);
setLibcallCallingConv(RTLIB::UREM_I32, CallingConv::AIE_PreserveAll_Vec);
setLibcallCallingConv(RTLIB::UREM_I64, CallingConv::AIE_PreserveAll_Vec);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see some other libcalls in the LegalizerHelper. Are these only the verified ones?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, these are only the ones I verified. Others could likely be included as well, but I wanted to keep this limited for now

In AIEs default calling convention, all vector registers are caller saved.
However, most compiler-rt builtin library functions do not use vector registers.
To avoid having to spill vectors to memory in the caller function,
we can attach a different calling convention to these library functions.
@F-Stuckmann F-Stuckmann force-pushed the kschwarz.aie.altcc.libcalls branch from 9660c19 to cebc746 Compare November 5, 2025 15:11
@F-Stuckmann F-Stuckmann requested a review from mludevid as a code owner November 5, 2025 15:11
: CalleeSavedRegs<(add lr, r8, r9, r10, r11, r12, r13, r14, r15, p6, p7)>;

def CSR_AIE2P_Vec
: CalleeSavedRegs<(add lr, r8, r9, r10, r11, r12, r13, r14, r15, p6, p7,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can we write this as an extension to CSR_AIE2P?

Copy link
Collaborator

Choose a reason for hiding this comment

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

e.g. factoring using a named common set?

: AIEBaseTargetLowering(TM, STI) {

if (VecCCLibcalls) {
setLibcallCallingConv(RTLIB::SINTTOFP_I32_F32,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: perhaps make a data-driven routine running on an array of function ids?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants