https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67797
Bug ID: 67797 Summary: [ARM] Unnecessary r0 saving for memset call Product: gcc Version: 5.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: d.salikhov at samsung dot com Target Milestone: --- Compiled with -Os and with -O2 (result is the same): #include <string.h> void *my_func(void *s, size_t n) { memset(s, 0, n); return s; } The generated code is following: 00000000 <my_func>: 0: e92d4010 push {r4, lr} 4: e1a02001 mov r2, r1 8: e1a04000 mov r4, r0 c: e3a01000 mov r1, #0 10: ebfffffe bl 0 <memset> 14: e1a00004 mov r0, r4 18: e8bd8010 pop {r4, pc} First, copying r0 into r4 is redundant as memset doesn't clobber r0. So the code could be reduced to: push {r4, lr} mov r2, r1 mov r1, #0 bl 0 <memset> pop {r4, pc} That in turn can be simplified more to: mov r2, r1 mov r1, #0 b 0 <memset>