Bug 11662 - [3.3 regression] wrong code for expr. with cast to long long and exclusive or
[3.3 regression] wrong code for expr. with cast to long long and exclusive or
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: rtl-optimization
3.3
: P1 critical
: 3.3.2
Assigned To: Eric Botcazou
: wrong-code
: 11181 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2003-07-24 14:59 UTC by heinrich.brand
Modified: 2003-09-07 10:03 UTC (History)
3 users (show)

See Also:
Host: sparc-sun-solaris2.8
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-07-24 18:40:33


Attachments
Proposed patch backported from 3.4 (558 bytes, patch)
2003-07-25 16:38 UTC, Christian Ehrhardt
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description heinrich.brand 2003-07-24 14:59:55 UTC
static unsigned  long long r;




void Test(unsigned long a, unsigned  long  b, unsigned  long long c){ 


    /* Failed with: r = (  (( a ^ b )  & c)  ) ; */


    r = (  (( (unsigned long long)a ^ (unsigned long long)b )  & c)  ) ;


    


    return;


}


main(){




 Test(1,2,3);


 if(r == 3){printf("PASSED\n"); return 0;}else{printf("FAILED\n");return 1;}




}
Comment 1 Andrew Pinski 2003-07-24 15:20:35 UTC
Does this work with -fno-delayed-branch?
I do not know the rules on sparc for delay slots of branch instructions so if it works with that then 
that is the problem because looking to at the asm looks right except for the store after the return.
Comment 2 heinrich.brand 2003-07-24 16:21:30 UTC
Subject: AW:  [SPARC] -O1: wrong code for expr. wi
	th cast to long long and exclusive or

No it fails with -01 -fno-delayed-branch too.

This is my assembler file for -O1 -S 
(code for the expression (  (( (unsigned long long)a ^ (unsigned long long)b )  & c)  )  is not in function Test. -fno-delayed-branch does not change function Test):

	.file	"x.c"
	.section	".text"
	.align 4
	.global Test
	.type	Test, #function
	.proc	020
Test:
	!#PROLOGUE# 0
	!#PROLOGUE# 1
	mov	0, %o4
	mov	0, %o5
	sethi	%hi(r), %g1
	retl
	std	%o4, [%g1+%lo(r)]
	.size	Test, .-Test
	.section	".rodata"
	.align 8
.LLC1:
	.asciz	"FAILED"
	.align 8
.LLC0:
	.asciz	"PASSED"
	.section	".text"
	.align 4
	.global main
	.type	main, #function
	.proc	04
main:
	!#PROLOGUE# 0
	save	%sp, -112, %sp
	!#PROLOGUE# 1
	mov	1, %o0
	mov	2, %o1
	mov	0, %o2
	call	Test, 0
	mov	3, %o3
	sethi	%hi(r), %g1
	or	%g1, %lo(r), %o5
	ld	[%g1+%lo(r)], %g1
	cmp	%g1, 0
	bne	.LL5
	sethi	%hi(.LLC1), %o0
	ld	[%o5+4], %g1
	cmp	%g1, 3
	bne	.LL5
	nop
	sethi	%hi(.LLC0), %o0
	call	puts, 0
	or	%o0, %lo(.LLC0), %o0
	b	.LL2
	mov	0, %i0
.LL5:
	call	puts, 0
	or	%o0, %lo(.LLC1), %o0
	mov	1, %i0
.LL2:
	nop
	ret
	restore
	.size	main, .-main
	.local	r
	.common	r,8,8
	.ident	"GCC: (GNU) 3.3"

-----Ursprüngliche Nachricht-----
Von: pinskia at physics dot uc dot edu [mailto:gcc-bugzilla@gcc.gnu.org]
Gesendet: Donnerstag, 24. Juli 2003 17:21
An: Brand, Heinrich
Betreff: [Bug optimization/11662] [SPARC] -O1: wrong code for expr. with
cast to long long and exclusive or


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at physics dot uc dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
            Summary|[SPARC] -O1: wrong code for |[SPARC] -O1: wrong code for
                   |expr. with cast to long long|expr. with cast to long long
                   |and exclusive or            |and exclusive or


------- Additional Comments From pinskia at physics dot uc dot edu  2003-07-24 15:20 -------
Does this work with -fno-delayed-branch?
I do not know the rules on sparc for delay slots of branch instructions so if it works with that then 
that is the problem because looking to at the asm looks right except for the store after the return.



------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.

-----Ursprüngliche Nachricht-----
Von: pinskia at physics dot uc dot edu [mailto:gcc-bugzilla@gcc.gnu.org]
Gesendet: Donnerstag, 24. Juli 2003 17:21
An: Brand, Heinrich
Betreff: [Bug optimization/11662] [SPARC] -O1: wrong code for expr. with
cast to long long and exclusive or


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at physics dot uc dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
            Summary|[SPARC] -O1: wrong code for |[SPARC] -O1: wrong code for
                   |expr. with cast to long long|expr. with cast to long long
                   |and exclusive or            |and exclusive or


------- Additional Comments From pinskia at physics dot uc dot edu  2003-07-24 15:20 -------
Does this work with -fno-delayed-branch?
I do not know the rules on sparc for delay slots of branch instructions so if it works with that then 
that is the problem because looking to at the asm looks right except for the store after the return.



------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.
Comment 3 Andrew Pinski 2003-07-24 18:40:33 UTC
Thanks for the asm, this looks like it is fixed on the mainline (20030714 at least with a cross-
compiler from powerpc-apple-darwin6.6):
        !#PROLOGUE# 0
        !#PROLOGUE# 1
        xor     %o0, %o1, %o0
        mov     %o0, %o1
        mov     0, %o0
        and     %o0, %o2, %o0
        and     %o1, %o3, %o1
        sethi   %hi(r.0), %g1
        retl
        std     %o0, [%g1+%lo(r.0)]

I do not have a cross-compiler to check on 3.3.1 prelease though.
Comment 4 Andrew Pinski 2003-07-24 20:21:11 UTC
I can confirm this in 3.3.1 (20030714) so this is bad, I am testing 3.2.3 to see if this is a 
regression.
Comment 5 Andrew Pinski 2003-07-24 20:40:46 UTC
3.2.3 also had the same problem
Comment 6 Andrew Pinski 2003-07-24 20:59:35 UTC
It worked in 3.0.4 so this is a regression.
Comment 7 heinrich.brand 2003-07-25 10:33:24 UTC
Subject: AW:  [3.3 regression][SPARC] -O1: wrong c
	ode for expr. with cast to long long and exclusive or

Hint: Compiled with "-01 -da" xor (one of the missing operations) is in .life but not in .combine

-----Ursprüngliche Nachricht-----
Von: pinskia at physics dot uc dot edu [mailto:gcc-bugzilla@gcc.gnu.org]
Gesendet: Donnerstag, 24. Juli 2003 23:00
An: Brand, Heinrich
Betreff: [Bug optimization/11662] [3.3 regression][SPARC] -O1: wrong
code for expr. with cast to long long and exclusive or


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at physics dot uc dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical
           Priority|P2                          |P1
            Summary|[3.3 only][SPARC] -O1: wrong|[3.3 regression][SPARC] -O1:
                   |code for expr. with cast to |wrong code for expr. with
                   |long long and exclusive or  |cast to long long and
                   |                            |exclusive or


------- Additional Comments From pinskia at physics dot uc dot edu  2003-07-24 20:59 -------
It worked in 3.0.4 so this is a regression.



------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.
Comment 8 Christian Ehrhardt 2003-07-25 16:36:21 UTC
This is a combine bug where CLOBBER expressions, that are meant to
make the combine attempt fail are folded and treated as zero.

It got fixed in 3.4 by this hunk:

2003-07-10  Denis Chertykov  <denisc@overta.ru>
            Richard Kenner <kenner@vlsi1.ultra.nyu.edu>

        * combine.c (gen_binary): Handle the CLOBBER rtx and
        don't build a binary operation with it.

I'll add the relevant backported hunk as a proposed patch. But it'll
take some time to get it bootstrapped and regresison tested.

    regards  Christian


Comment 9 Christian Ehrhardt 2003-07-25 16:38:07 UTC
Created attachment 4479 [details]
Proposed patch backported from 3.4
Comment 10 Christian Ehrhardt 2003-07-27 17:45:47 UTC
The testsuite (c,c++) completed. There were these two unexpected failures.
Neither of these seems to be new:

FAIL: gcc.dg/duff-2.c (test for excess errors)
FAIL: g++.other/decl5.C caused compiler crash

As this is a regression, a wrong code generation bug and a patch is
availiable I retarget this for 3.3.1. Not sure if it is too late or not.

Comment 11 Andrew Pinski 2003-07-28 03:06:32 UTC
Those two failures are unrelated to the patch as g++.other/decl5.C efects i686 also and 
gcc.dg/duff-2.c effects powerpc also.
Comment 12 Mark Mitchell 2003-08-03 16:01:11 UTC
Postponed until GCC 3.3.2.
Comment 13 Andrew Pinski 2003-08-03 16:19:18 UTC
*** Bug 11181 has been marked as a duplicate of this bug. ***
Comment 14 Eric Botcazou 2003-09-06 18:00:06 UTC
Christian's patch looks good. I'm going to retest it and resubmit it for
inclusion in GCC 3.3.2.
Comment 15 CVS Commits 2003-09-07 09:59:18 UTC
Subject: Bug 11662

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	ebotcazou@gcc.gnu.org	2003-09-07 09:59:14

Modified files:
	gcc            : ChangeLog combine.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: 20030907-1.c 

Log message:
	PR optimization/11662
	Backport from mainline:
	
	2003-07-10  Denis Chertykov  <denisc@overta.ru>
	Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
	
	* combine.c (gen_binary): Handle the CLOBBER rtx and
	don't build a binary operation with it.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.726&r2=1.16114.2.727
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/combine.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.325.2.9&r2=1.325.2.10
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.268&r2=1.2261.2.269
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20030907-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1

Comment 16 Eric Botcazou 2003-09-07 10:03:35 UTC
See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00400.html