<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/88300>88300</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[M68k] Inefficient function call/return sequences
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
n8pjl
</td>
</tr>
</table>
<pre>
```c
short bar(short);
short foo(short x) {
return bar(x);
}
```
`gcc -O1` produces:
```asm
foo:
move.w 6(%sp),%a0
move.l %a0,-(%sp)
jsr bar
addq.l #4,%sp
rts
```
while `clang -O1 -fomit-frame-pointer` produces:
```asm
foo:
suba.l #4, %sp
move.w (10,%sp), %d0
ext.l %d0
move.l %d0, (%sp)
jsr bar
ext.l %d0
adda.l #4, %sp
rts
```
The m68k abi does not expect byte or word parameters or return values to be extended at all, thus both `ext.l` instructions can be omitted, as GCC (and the Sierra C Compiler) does.
While clang puts the {sign,zero}ext attribute on all i1, i8, and i16 parameters and return values, removing that attribute does not eliminate argument value extension:
```asm
foo:
suba.l #4, %sp
move.w (10,%sp), %d0
and.l #65535, %d0
move.l %d0, (%sp)
jsr bar
adda.l #4, %sp
rts
```
The following optimizations can be performed on the sequence, in rough increasing order of difficulty:
- Omit frame pointers by default (#75013)
- Using quick variant of move, add, and sub instructions
- Merging stack adjustment with move, using predecrement addressing mode
- movem optimization (not relevant here)
- Remove unnecessary extensions of sub-register-width values
- Detect and perform sibcall optimization on entire sequence (which GCC performs for `-O2` and greater)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVl1v6jgQ_TXmZRSUOCSBBx5uQaz24arSfmifnXiSuE3s1B_Q3l-_GhMKdNvVSvdhIwTBnjkzc-Z4EuGc6jTilhUPrNgvRPC9sVu9np6GRW3k25aV6fnTsHTP0m-uN9ZDLSzj63jP-IblD-fNW5PWmIsJvDK-AVbNVgAAFn2wesZ5vcOo9vPNJf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