From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29254 invoked by alias); 25 Apr 2003 10:26:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 29232 invoked by uid 71); 25 Apr 2003 10:26:00 -0000 Resent-Date: 25 Apr 2003 10:26:00 -0000 Resent-Message-ID: <20030425102600.29231.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org, Erwin.Unruh@fujitsu-siemens.com Resent-Reply-To: gcc-gnats@gcc.gnu.org, Heinrich.Brand@fujitsu-siemens.com Received: (qmail 28716 invoked by uid 48); 25 Apr 2003 10:22:31 -0000 Message-Id: <20030425102231.28715.qmail@sources.redhat.com> Date: Fri, 25 Apr 2003 10:26:00 -0000 From: Heinrich.Brand@fujitsu-siemens.com Reply-To: Heinrich.Brand@fujitsu-siemens.com To: gcc-gnats@gcc.gnu.org Cc: Erwin.Unruh@fujitsu-siemens.com X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) X-GNATS-Notify: Erwin.Unruh@fujitsu-siemens.com Subject: optimization/10494: gcc 3.3 20030407 optimization based on SSA "-O2 -fssa" removes needed code X-SW-Source: 2003-04/txt/msg01085.txt.bz2 List-Id: >Number: 10494 >Category: optimization >Synopsis: gcc 3.3 20030407 optimization based on SSA "-O2 -fssa" removes needed code >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Fri Apr 25 10:26:00 UTC 2003 >Closed-Date: >Last-Modified: >Originator: Heinrich Brand >Release: gcc version 3.3 20030407 (prerelease) >Organization: >Environment: SunOS 5.8 sparc >Description: The test below compiles and executes successfully with -O2 but fails with -O2 -fssa. The difference of the disassembled code shows that with -O2 -fssa a needed instruction is missing so a function does not return a value (but should return a value). (Source code is in How-To-Repeat.) ******************************************************************* The dissembled code of both cases ("-O2" OK and "-O2 -fssa" wrong) : ******************************************************************* -O2 : f0() 0: 81 c3 e0 08 jmp %o7 + 8 4: c0 22 00 00 st %g0, [%o0] f1() 8: 9d e3 bf 88 save %sp, -120, %sp c: c0 27 bf ec st %g0, [%fp - 20] 10: 7f ff ff fc call f0 14: 90 07 bf ec add %fp, -20, %o0 18: f0 07 bf ec ld [%fp - 20], %i0 1c: 01 00 00 00 nop 20: 81 c7 e0 08 ret 24: 81 e8 00 00 restore ******************************************************************* -O2 -fssa : f0() 0: 81 c3 e0 08 jmp %o7 + 8 4: c0 22 00 00 st %g0, [%o0] f1() 8: 9d e3 bf 88 save %sp, -120, %sp c: 7f ff ff fd call f0 10: 90 07 bf ec add %fp, -20, %o0 ---------------- %i0 is not set but %o0 is used in main ! ------ 14: 01 00 00 00 nop 18: 81 c7 e0 08 ret 1c: 81 e8 00 00 restore ******************************************************************* both cases (only offsets differ): --------------- %o0 is in main not set otherwise ------------------ main() 20: 9d e3 bf 90 save %sp, -112, %sp 24: 40 00 00 00 call 0x24 28: 01 00 00 00 nop 2c: 80 a2 20 00 cmp %o0, 0 30: 32 80 00 05 bne,a 0x44 ... ******************************************************************* End of the disassembled code of the first test. ******************************************************************* Another test: ******************************************************************* If in the source code "f0(&k);" is replaced by "*(&k) = 0;" The following code is generated: ******************************************************************* The dissembled code of both cases ("-O2" OK and "-O2 -fssa" wrong) : ******************************************************************* -O2: f1() 8: 81 c3 e0 08 jmp %o7 + 8 c: 90 10 20 00 clr %o0 ******************************************************************* -O2 -fssa: f1() 8: 01 00 00 00 nop c: 81 c3 e0 08 jmp %o7 + 8 ----------------- %o0 is not set but used in main --------------------- 10: 01 00 00 00 nop ******************************************************************* both cases (only offsets differ): --------------- %o0 is in main not set otherwise ------------------ main() 14: 9d e3 bf 90 save %sp, -112, %sp 18: 40 00 00 00 call 0x18 1c: 01 00 00 00 nop 20: 80 a2 20 00 cmp %o0, 0 24: 32 80 00 05 bne,a 0x38 ... ******************************************************************* End of the disassembled code of the second test. >How-To-Repeat: The the test with output FAILED can be repeated by: Compile following source code with gcc 3.3 20030407 -O2 -fssa and execute resulting program int printf(const char *format, ...); static void f0 (long *y) { *y = 0; return; } int f1 () { long k=0; f0(&k); return k; } int main () { if (f1() == 0) printf("SUCCESSFUL\n"); else printf("FAILED\n"); return 0; } >Fix: Do not use "-O2 -fssa" . >Release-Note: >Audit-Trail: >Unformatted: