Bug 15948 - [3.4 Regression] THUMB: ICE with non-commutative cbranch
Summary: [3.4 Regression] THUMB: ICE with non-commutative cbranch
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.0
: P1 critical
Target Milestone: 3.4.2
Assignee: Richard Earnshaw
Keywords: ice-on-valid-code
: 16267 (view as bug list)
Depends on:
Reported: 2004-06-11 19:37 UTC by Dan Bornstein
Modified: 2004-08-25 16:10 UTC (History)
3 users (show)

See Also:
Target: arm-unknown-elf
Known to work:
Known to fail:
Last reconfirmed: 2004-06-22 11:21:23

Provisional patch (616 bytes, patch)
2004-06-22 11:23 UTC, Richard Earnshaw
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Bornstein 2004-06-11 19:37:59 UTC
Compiling the following file with -O2 causes an assert failure inside gcc:

    void ouch(int *s)
        int e = s[0];
        if ((e & 2) == 0) {

(That's it.) The reported error is:

    $ arm-elf-gcc -save-temps -c ouch.c -mthumb -O2 -o ouch.o
    ouch.c: In function `ouch':
    ouch.c:9: internal compiler error: in do_output_reload, at reload1.c:6895
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Here's the salient part of reload1.c:

    /* If is a JUMP_INSN, we can't support output reloads yet.  */
    if (GET_CODE (insn) == JUMP_INSN)
      abort (); // LINE 6895

Here's how I configured and built the compiler:

$ tar -xjvf gcc-core-3.4.0.tar.bz2
$ cd gcc-3.4.0
$ ./configure --prefix=/usr/local/armdev --target=arm-elf --with-newlib --enable-languages=c

The following lines were uncommented in gcc/config/arm/t-arm-elf:

MULTILIB_OPTIONS    += mno-thumb-interwork/mthumb-interwork
MULTILIB_DIRNAMES   += normal interwork
MULTILIB_EXCEPTIONS += *mapcs-26/*mthumb-interwork*

$ make
$ sudo make install

In case it matters, I'm currently using binutils-2.15.
Comment 1 Richard Earnshaw 2004-06-22 11:21:22 UTC
Confirmed.  The compiler is using a non-commutative operation that sets the
condition codes.  Unfortunately, the register allocator has dug a pit that
reload doesn't know how to climb out of.  The attached patch should give it a
suitable step up again.

The other cbranch insns in the machine description need auditing to see if they
might suffer from the same problem.
Comment 2 Richard Earnshaw 2004-06-22 11:23:09 UTC
Created attachment 6603 [details]
Provisional patch

Fixes the specific test case, but further checking for similar cases needed.
Comment 3 Dan Bornstein 2004-06-22 17:17:48 UTC
I've confirmed that the patch fixes this bug on my build. Thanks!

I originally noticed a couple other files in the system that I'm working on that appeared to cause the 
same failure. I'll see whether or not this patch affects them as well.
Comment 4 Dan Bornstein 2004-06-22 18:22:51 UTC
Confirmed that my original (undistilled) source files compile without complaint and appear to run 
correctly with this patch.
Comment 5 CVS Commits 2004-06-23 11:39:40 UTC
Subject: Bug 15948

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rearnsha@gcc.gnu.org	2004-06-23 11:39:33

Modified files:
	gcc            : ChangeLog 
	gcc/config/arm : arm.md 

Log message:
	* PR target/15948
	* arm.md (bicsi3_cbranch): Add alternative to handle tying operands
	one and two.


Comment 6 Richard Earnshaw 2004-06-23 11:43:20 UTC
Checking the other cbranch patterns shows no obvious similar cases to this one.

I've installed the patch on the trunk and will pull it up to the branch once
3.4.2 has shipped.
Comment 7 Richard Earnshaw 2004-06-30 10:25:59 UTC
*** Bug 16267 has been marked as a duplicate of this bug. ***
Comment 8 Mark Mitchell 2004-08-23 19:19:09 UTC
Since Richard has indicated that he's waiting for 3.4.2, I've pushed the target
milestone back to 3.4.3.
Comment 9 Richard Earnshaw 2004-08-24 09:08:26 UTC
Hmm, that was a typo, I meant to put 'until after 3.4.1' or 'for 3.4.2' but
somehow managed to put something else instead.

There's no reason (now that it's hand some exposure on mainline) why this patch
shouldn't be pulled up in time for the 3.4.2 release.

Comment 10 CVS Commits 2004-08-25 15:46:35 UTC
Subject: Bug 15948

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	rearnsha@gcc.gnu.org	2004-08-25 15:46:20

Modified files:
	gcc            : ChangeLog 
	gcc/config/arm : arm.md 

Log message:
	* PR target/15948
	* arm.md (bicsi3_cbranch): Add alternative to handle tying operands
	one and two.


Comment 11 CVS Commits 2004-08-25 16:07:48 UTC
Subject: Bug 15948

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	csl-arm-branch
Changes by:	rearnsha@gcc.gnu.org	2004-08-25 16:07:39

Modified files:
	gcc            : ChangeLog.csl-arm 
	gcc/config/arm : arm.md 

Log message:
	* PR target/15948
	* arm.md (bicsi3_cbranch): Add alternative to handle tying operands
	one and two.


Comment 12 Richard Earnshaw 2004-08-25 16:10:18 UTC
Patch applied to 3.4 and csl-arm branches