This is an archive of the discontinued LLVM Phabricator instance.

[AVR] Generate 'rcall' instead of 'call' on avr2 and avr25
ClosedPublic

Authored by benshi001 on Mar 12 2022, 10:43 PM.

Details

Summary

The 'call' (long call) instruction is available on avr3 and above,
and devices in avr2 and avr25 should use the 'rcall' (short call)
instruction for function calls.

Diff Detail

Event Timeline

benshi001 created this revision.Mar 12 2022, 10:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2022, 10:43 PM
Herald added subscribers: Jim, hiraditya. · View Herald Transcript
benshi001 requested review of this revision.Mar 12 2022, 10:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2022, 10:43 PM
aykevl accepted this revision.Mar 22 2022, 5:08 PM

Looks good to me!

As a possible optimization, you could look into using rcall instead of call instructions when the target is close enough. For example, here: https://godbolt.org/z/rEz9j71dq (apparently avr-gcc doesn't do this optimization).

int foo(int a, int b) {
    return a + b;
}

int bar(int a, int b) {
    return foo(a, b) + 3;
}

If -ffunction-sections is not used, rcall is both shorter in code size and faster in execution speed.
(This is just an idea, unrelated to this patch).

This revision is now accepted and ready to land.Mar 22 2022, 5:08 PM
This revision was landed with ongoing or failed builds.Mar 22 2022, 7:00 PM
This revision was automatically updated to reflect the committed changes.

Looks good to me!

As a possible optimization, you could look into using rcall instead of call instructions when the target is close enough. For example, here: https://godbolt.org/z/rEz9j71dq (apparently avr-gcc doesn't do this optimization).

int foo(int a, int b) {
    return a + b;
}

int bar(int a, int b) {
    return foo(a, b) + 3;
}

If -ffunction-sections is not used, rcall is both shorter in code size and faster in execution speed.
(This is just an idea, unrelated to this patch).

Thanks. I have created an issue to note this task.
https://github.com/llvm/llvm-project/issues/54508