Bug 10519

Summary: optimization based on SSA "-O2 -fssa" uses wrong register
Product: gcc Reporter: heinrich.brand
Component: rtl-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED WONTFIX    
Severity: normal CC: gcc-bugs
Priority: P3 Keywords: wrong-code
Version: 3.3   
Target Milestone: ---   
Host: sparc-sun-solaris2.8 Target: sparc-sun-solaris2.8
Build: sparc-sun-solaris2.8 Known to work:
Known to fail: Last reconfirmed: 2003-06-04 19:51:50

Description Andrew Pinski 2003-04-28 08:38:13 UTC
From: Andrew Pinski <pinskia@physics.uc.edu>
To: Heinrich.Brand@fujitsu-siemens.com
Cc: gcc-gnats@gcc.gnu.org, Erwin.Unruh@fujitsu-siemens.com
Subject: Re: optimization/10519: optimization based on SSA "-O2 -fssa" uses wrong register
Date: Mon, 28 Apr 2003 08:38:13 -0400

 -fssa is not ready for production use, from  
 <http://gcc.gnu.org/onlinedocs/gcc/Optimize- 
 Options.html#Optimize%20Options>:
   Users should not specify this option, since it is not yet ready for  
 production use.
 
 Since -fssa is going away in favor of something different, do not use  
 this flag.
 
 Thanks,
 Andrew Pinski
Comment 1 heinrich.brand 2003-04-28 12:26:00 UTC
The test below compiles and executes successfully
with -O2 but fails with -O2 -fssa. The  disassembled code
differs in one register in one place. A function should add
2 input registers and return the sum but in the "-O2 -fssa" case
only one register is used in the add instruction.

(Source code is in How-To-Repeat.) 

*******************************************************************
The dissembled code of both cases ("-O2" OK and "-O2 -fssa" wrong) :
*******************************************************************
-O2 :

fy()
           0:  81 c3 e0 08         jmp          %o7 + 8
           4:  90 02 00 09         add          %o0, %o1, %o0


*******************************************************************
-O2 -fssa :

fy()
           0:  81 c3 e0 08         jmp          %o7 + 8
-------------------- wrong register in add: ------------------------ 
           4:  90 02 00 08         add          %o0, %o0, %o0
                                                       

*******************************************************************
both cases (only offsets differ):

main()
           8:  9d e3 bf 90         save         %sp, -112, %sp
           c:  92 10 20 04         mov          4, %o1
          10:  40 00 00 00         call         0x10
          14:  90 10 20 03         mov          3, %o0
          18:  80 a2 20 07         cmp          %o0, 7
...
*******************************************************************
End of the disassembled code.

Release:
Release: gcc version 3.3 20030407 (prerelease)

Environment:
SunOS 5.8 sparc

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, ...);
int f(int a, int b){
        int *xa,*xb;
        xa=&a;xb=&b;
        return *xa+*(xb);
}
int main(){
  if( f(3,4)==7 )
    printf("SUCCESSFUL\n");
  else
   printf("FAILED\n");
  return 0;
}
Comment 2 heinrich.brand 2003-04-28 12:26:00 UTC
Fix:
Do not use "-O2 -fssa" .
Comment 3 Dara Hazeghi 2003-06-01 23:09:54 UTC
Hello,

I can confirm this problem on i686-linux. gcc 3.2.3 is fine, but both 3.3 branch and mainline 
(20030527) fail... I agree with Andrew that -fssa is probably going away in its current form, but 
still, this is broken, so I think we should probably just make this a low-priority bug, at least until -
fssa finally is removed. Or should this perhaps be mapped to the RESOLVED: WONTFIX category?

Dara
Comment 4 Dara Hazeghi 2003-06-04 19:51:50 UTC
Confirmed (at least for now)...
Comment 5 Andrew Pinski 2003-07-11 16:52:22 UTC
-fssa is being removed from the mainline <http://gcc.gnu.org/ml/gcc/2003-07/
msg00070.html> so we will not fix this. The workaround is not to use -fssa at all.