Bug 12028

Summary: [3.4 Regression] powerpc-eabispe produces bad sCOND operation
Product: gcc Reporter: Dara Hazeghi <dhazeghi>
Component: targetAssignee: Aldy Hernandez <aldyh>
Status: RESOLVED FIXED    
Severity: critical CC: gcc-bugs
Priority: P1 Keywords: ice-checking, wrong-code
Version: 3.4.0   
Target Milestone: 3.4.1   
Host: Target: powerpc-eabispe
Build: Known to work: 4.0.0
Known to fail: 3.4.0 Last reconfirmed: 2003-11-29 21:36:53
Attachments: unreduced testcase
Reduced testcase

Description Dara Hazeghi 2003-08-21 23:32:44 UTC
Building gcc for powerpc-eabispe target on mainline (combined tree):
../combined/configure --target=powerpc-eabispe --enable-languages=c,c++,objc
fails with:
./xgcc -B./ -B/usr/local/powerpc-eabispe/bin/ -isystem /usr/local/powerpc-eabispe/include -
isystem /usr/local/powerpc-eabispe/sys-include -L/home/dara/mainline/objdir/gcc/../ld -O2  -
DIN_GCC -DCROSS_COMPILE   -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-
prototypes -isystem ./include   -g  -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -Dinhibit_libc -I. 
-I. -I../../combined/gcc -I../../combined/gcc/. -I../../combined/gcc/config -I../../combined/gcc/
../include   -DL_divdi3 -c ../../combined/gcc/libgcc2.c -fexceptions -fnon-call-exceptions -o 
libgcc/./_divdi3.o
../../combined/gcc/libgcc2.c: In function `__divdi3':

../../combined/gcc/libgcc2.c:1066: internal compiler error: in ccr_bit, at config/rs6000/
rs6000.c:8136
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
make[1]: *** [libgcc/./_divdi3.o] Error 1
make[1]: Leaving directory `/home/dara/mainline/objdir/gcc'
make: *** [stmp-multilib] Error 2

The testcase does not ICE if -O1 or lower is specified.
Comment 1 Dara Hazeghi 2003-08-21 23:34:15 UTC
Created attachment 4638 [details]
unreduced testcase

fails with cross cc1 to powerpc-easbispe with -O2 or higher optimization.
Comment 2 Andrew Pinski 2003-08-23 17:25:32 UTC
I think this is a regression from 3.3.
Comment 3 Zdenek Dvorak 2003-09-17 13:34:40 UTC
Created attachment 4774 [details]
Reduced testcase
Comment 4 Andrew Pinski 2003-09-18 06:37:52 UTC
Since  Zdenek reduced this, I am marking as confirmed.
Comment 5 janis187 2003-09-18 20:46:18 UTC
The regression in PR 12028 was introduced or exposed by this patch:

--- gcc/gcc/ChangeLog ---

2003-05-03  Geoffrey Keating  <geoffk@apple.com>

        * config/rs6000/rs6000.c (scc_comparison_operator): Make equivalent
        to branch_positive_comparison_operator.
        (ccr_bit): Check that sCOND conditions are actually a positive bit.
        (print_operand): Remove %D substitution.
        (rs6000_emit_sCOND): Generate complement operation to ensure that
        sCOND input is a positive bit.
        * config/rs6000/rs6000.md: Rearrange sCOND templates to be in the
        same order as bCOND, and add the missing ones.  Remove the %D
        substitutions from the scc patterns.

        * simplify-rtx.c (simplify_relational_operation): Add case for
        ! (fabs(x) < 0.0).

(http://gcc.gnu.org/ml/gcc-patches/2003-05/msg00338.html)

The regression hunt took place on i686-pc-linux-gnu with a cross compiler
for powerpc-eabispe, using the reduced test case from comment #3 with -O2.
Comment 6 Andrew Pinski 2003-11-09 21:41:28 UTC
The problem is part of the patch:
  /* When generating a sCOND operation, only positive conditions are
     allowed.  */
  if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
      && code != GTU && code != LTU)
    abort ();
Down below that, there is case for NE (which is the code at this point).
Comment 7 Geoff Keating 2003-11-10 01:01:21 UTC
Subject: Re:  [3.4 Regression] powerpc-eabispe: ICE building __divdi3.o: in ccr_bit, at config/rs6000/rs6000.c:8136

"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

> ------- Additional Comments From pinskia at gcc dot gnu dot org  2003-11-09 21:41 -------
> The problem is part of the patch:
>   /* When generating a sCOND operation, only positive conditions are
>      allowed.  */
>   if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
>       && code != GTU && code != LTU)
>     abort ();
> Down below that, there is case for NE (which is the code at this point).

The check is clearly correct.  In the SPE case, both 'EQ' and 'NE' are
'base_bit + 1', but for a sCOND operation the bit must be set when the
condition is true, and EQ and NE are mutually exclusive.  So the
problem must be somewhere else, and removing the check would only
guarantee bad code generation.

Comment 8 Andrew Pinski 2004-02-10 02:00:45 UTC
This was caused by your patch are you going to fix it?
Comment 9 GCC Commits 2004-02-10 03:45:08 UTC
Subject: Bug 12028

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	geoffk@gcc.gnu.org	2004-02-10 03:45:04

Modified files:
	gcc            : ChangeLog 
	gcc/config/rs6000: rs6000.c 

Log message:
	PR 12028
	* config/rs6000/rs6000.c (ccr_bit): Don't let consistency check
	failure stop compilation, just print helpful message.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.170&r2=2.2326.2.171
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/rs6000/rs6000.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.576.2.6&r2=1.576.2.7

Comment 10 Geoff Keating 2004-02-10 03:50:40 UTC
The previous patch suppresses the build failure on the 3.4 branch.  However, the underlying problem is 
still there.  I believe it has been there since the e500 port was added.
Comment 11 Andrew Pinski 2004-04-20 14:51:55 UTC
Should be fixed in 3.5.0 by Aldy's rewrite.
Comment 12 Aldy Hernandez 2004-04-29 19:09:16 UTC
Fixed on 3.4 branch by http://gcc.gnu.org/ml/gcc-patches/2004-04/msg01926.html