public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mhlavink at redhat dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/52415] memcpy to local variable generates unnecessary stack frame for armv7
Date: Wed, 18 Apr 2012 12:48:00 -0000	[thread overview]
Message-ID: <bug-52415-4-YtQo0j8btj@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-52415-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52415

--- Comment #8 from Michal Hlavinka <mhlavink at redhat dot com> 2012-04-18 12:22:34 UTC ---
Created attachment 27182
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27182
pre-processed reproducer (avr)

(In reply to comment #7)
> Would you please post a complete test case to reproduce?
> See http://gcc.gnu.org/bugs/#need

$ avr-gcc --version
avr-gcc (Fedora 4.7-0.fc17.1.20120302) 4.7.1 20120414 (prerelease)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

(ignore old date in package name)

$ uname -ra
Linux nbone.mihlnet 3.3.0-8.fc16.x86_64 #1 SMP Thu Mar 29 18:37:19 UTC 2012
x86_64 x86_64 x86_64 GNU/Linux

command for compilation:
avr-g++ -mmcu=atmega2560  -gdwarf-2 -DF_CPU=16000000UL -O1 -Wall
-Wno-unused-variable -fno-inline-small-functions -fwhole-program testitb.cpp
--output test0.S  -S

In reproducer there are 3 options for structure swapping. First two reproduce
the problem. The last one works. This problem does not exist in avr-gcc 4.6.2

Original code:
DirEnt            tmp = eeFs.files[i_fileId1];
eeFs.files[i_fileId1] = eeFs.files[i_fileId2];
eeFs.files[i_fileId2] = tmp;
s_sync_write = true;
EeFsFlushDirEnt(i_fileId1);
EeFsFlushDirEnt(i_fileId2);

What happens:
it copies structures and then it calls EeFsFlushDirEnt but with corrupted
values.
.L__stack_usage = 4
    mov r28,r22
.LBB2:
    .loc 1 50 0
    mov r18,r24
    ldi r19,0
    movw r26,r18
    lsl r26
    rol r27
    add r26,r18
    adc r27,r19
    subi r26,lo8(-(eeFs))
    sbci r27,hi8(-(eeFs))
    adiw r26,4
    ld r24,X+
    ld r25,X+
    ld r26,X
    sbiw r26,4+2
.LVL2:
    .loc 1 51 0
    mov r30,r22
    ldi r31,0
    movw r12,r30
    lsl r12
    rol r13
    add r30,r12
    adc r31,r13
    subi r30,lo8(-(eeFs))
    sbci r31,hi8(-(eeFs))
    ldd r12,Z+4
    ldd r13,Z+5
    ldd r14,Z+6
    adiw r26,4
    st X+,r12
    st X+,r13
    st X,r14
    .loc 1 52 0
    std Z+4,r18
    std Z+5,r19
    std Z+6,r20
.LVL3:
    .loc 1 60 0
    call _ZL15EeFsFlushDirEnth
.LVL4:
    .loc 1 61 0
    mov r24,r28
    call _ZL15EeFsFlushDirEnth

First call is made with r24 that got overwritten during structure copy.
In the third structure copy code (the working one) r24 is not changed.

I'm not too good in assembler interpretation, so this is what it seems to me is
happening, but I can be wrong and there can be different problem than r24.


  parent reply	other threads:[~2012-04-18 12:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-28 10:40 [Bug target/52415] New: " jay.foad at gmail dot com
2012-02-28 11:51 ` [Bug target/52415] " rguenth at gcc dot gnu.org
2012-02-28 12:02 ` jay.foad at gmail dot com
2012-02-28 12:17 ` rguenth at gcc dot gnu.org
2012-02-28 12:39 ` jakub at gcc dot gnu.org
2012-02-28 13:07 ` jay.foad at gmail dot com
2012-04-05  8:13 ` mhlavink at redhat dot com
2012-04-17  8:30 ` gjl at gcc dot gnu.org
2012-04-18 12:48 ` mhlavink at redhat dot com [this message]
2012-04-18 20:02 ` gjl at gcc dot gnu.org
2012-06-06 11:00 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-52415-4-YtQo0j8btj@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).