From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 34280 invoked by alias); 1 Oct 2015 14:19:56 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 34253 invoked by uid 48); 1 Oct 2015 14:19:52 -0000 From: "d.salikhov at samsung dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/67797] New: [ARM] Unnecessary r0 saving for memset call Date: Thu, 01 Oct 2015 14:19:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 5.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: d.salikhov at samsung dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-10/txt/msg00052.txt.bz2 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 void *my_func(void *s, size_t n) { memset(s, 0, n); return s; } The generated code is following: 00000000 : 0: e92d4010 push {r4, lr} 4: e1a02001 mov r2, r1 8: e1a04000 mov r4, r0 c: e3a01000 mov r1, #0 10: ebfffffe bl 0 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 pop {r4, pc} That in turn can be simplified more to: mov r2, r1 mov r1, #0 b 0