From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8563 invoked by alias); 18 Apr 2012 12:48:30 -0000 Received: (qmail 8493 invoked by uid 22791); 18 Apr 2012 12:48:27 -0000 X-SWARE-Spam-Status: No, hits=-4.2 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED,TW_CP,TW_GD,TW_OV X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 18 Apr 2012 12:47:40 +0000 From: "mhlavink at redhat dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: mhlavink at redhat dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2012-04/txt/msg01500.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52415 --- Comment #8 from Michal Hlavinka 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.