This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

optimization/10494: gcc 3.3 20030407 optimization based on SSA "-O2 -fssa" removes needed code


>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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]