An instruction like this will need to allocate some stack space for the last parameter:
%x = call addrspace(1) i16 @bar(i64 undef, i64 undef, i16 undef, i16 0)
This worked fine when passing an actual value (in this case 0). However, when passing undef, no value was pushed to the stack and therefore no push instructions were created. This caused an unbalanced stack leading to interesting results.
This commit fixes that by replacing the push logic with a regular stack adjustment and stack-relative load/stores. This is less efficient but at least it correctly compiles the code.
I can think of a few improvements in the future:
- The stack should have been adjusted in the function prologue when there are no allocas in the function.
- Many (if not most) stack adjustments can be replaced by pushing/popping the values directly. Exactly like the previous code attempted but didn't do correctly.
- Small stack adjustments can be done more efficiently with a few push/pop instructions (pushing/popping bogus values), both for code size and for speed.
All in all, as long as there are no allocas in the function I think that is almost always more efficient to emit regular push/pop instructions. This is however left for future optimizations.
Together with D78579 this fixes two additional tests in compiler-rt: powidf2_test.c and powixf2_test.c.