Bug 49030 - ICE in get_arm_condition_code, at config/arm/arm.c:17180
Summary: ICE in get_arm_condition_code, at config/arm/arm.c:17180
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: rsandifo@gcc.gnu.org
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords: ice-on-valid-code
Depends on:
Reported: 2011-05-17 19:11 UTC by Ryan Mansfield
Modified: 2012-01-18 12:04 UTC (History)
6 users (show)

See Also:
Host: x86_64-linux-gnu
Target: arm-unknown-linux-gnueabi
Build: x86_64-linux-gnu
Known to work:
Known to fail: 4.7.0
Last reconfirmed: 2011-05-20 09:50:09

preprocessed source (225 bytes, text/plain)
2011-05-17 19:11 UTC, Ryan Mansfield
more reduced test case, ICEs at -O1 for armv5te and armv6 (111 bytes, text/plain)
2011-06-12 15:23 UTC, Mikael Pettersson

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Mansfield 2011-05-17 19:11:01 UTC
Created attachment 24268 [details]
preprocessed source

$ ./xgcc -v
Using built-in specs.
Target: arm-unknown-linux-gnueabi
Configured with: ../configure --target=arm-unknown-linux-gnueabi --prefix=/home/ryan/x-tools/arm-unknown-linux-gnueabi --with-sysroot=/home/ryan/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi//sys-root --disable-multilib --with-local-prefix=/home/ryan/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace target_alias=arm-unknown-linux-gnueabi --enable-languages=c++ --disable-shared --disable-libmudflap --disable-libssp
Thread model: posix
gcc version 4.7.0 20110517 (experimental) [trunk revision 173832] (GCC) 
$ ./xgcc -B.  -O1 ~/ice.i
/home/ryan/ice.i: In function 'bar':
/home/ryan/ice.i:33:1: internal compiler error: in get_arm_condition_code, at config/arm/arm.c:17180
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Ian Bolton 2011-05-20 09:50:09 UTC
I haven't been able to reproduce this.  Please can you include the args that are being sent to cc1.
Comment 2 Ryan Mansfield 2011-05-20 13:04:58 UTC
With rev173940

$ ./cc1 -fpreprocessed ice.i -quiet -O1 
ice.i: In function 'bar':
ice.i:33:1: internal compiler error: in get_arm_condition_code, at config/arm/arm.c:17021
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 3 Ian Bolton 2011-05-20 13:46:00 UTC
I was hoping the compiler command would tell me what -mcpu it was defaulting to.

Anyway, I have managed to reproduce it now, by compiling as follows:

  cc1 -fpreprocessed 49030.i -quiet -O1 -o 49030.s -mcpu=arm7tdmi -marm

Note that it all works with -mthumb and/or -mcpu=cortex-a9.

I have tried this with my old toolchain and it is broken as far back as r164700.
Comment 4 Ryan Mansfield 2011-05-20 14:41:41 UTC
(In reply to comment #3)
> I was hoping the compiler command would tell me what -mcpu it was defaulting
> to.

I'm using an arm-unknown-linux-gnueabi configuration which defaults an arm10tdmi.

linux-eabi.h:#define SUBTARGET_CPU_DEFAULT TARGET_CPU_arm10tdmi
Comment 5 Michael Hope 2011-06-09 01:34:47 UTC
The same assert is seen in https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/689887 in Thumb-2 mode on trunk r174795.

Chung-Lin posted a patch at http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00790.html but there are bootstrap issues.

Adding -fno-if-conversion works around the problem.
Comment 6 Mikael Pettersson 2011-06-10 19:02:07 UTC
It's caused by r161764:

Author: sandra
Date: Sat Jul  3 01:00:37 2010
New Revision: 161764

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161764
2010-07-02  Daniel Jacobowitz  <dan@codesourcery.com>
	    Julian Brown  <julian@codesourcery.com>
	    Sandra Loosemore <sandra@codesourcery.com>

	* config/arm/arm.c (arm_canonicalize_comparison): Canonicalize DImode
	comparisons.  Adjust to take both operands.
	(arm_select_cc_mode): Handle DImode comparisons.
	(arm_gen_compare_reg): Generate a scratch register for DImode
	comparisons which require one.  Use xor for Thumb equality checks.
	(arm_const_double_by_immediates): New.
	(arm_print_operand): Allow 'Q' and 'R' for constants.
	(get_arm_condition_code): Handle new CC_CZmode and CC_NCVmode.
Comment 7 Mikael Pettersson 2011-06-12 15:23:40 UTC
Created attachment 24503 [details]
more reduced test case, ICEs at -O1 for armv5te and armv6

Using this slightly more reduced test case I've found that gcc transforms

(set (reg:CC_NCV ...) (compare:CC_NCV (reg:DI ...) (const_int 1 ...)))
(if_then_else (ge (reg:CC_NCV ...) ...) ...)


(set (reg:CC_NCV ...) (compare:CC_NCV (reg:DI ...) (const_int 0 ...)))
(if_then_else (gt (reg:CC_NCV ...) ...)

because ifcvt calls noce_get_condition which calls canonicalize_condition, and the latter has a general rule to transform (GE x const) to (GT x const-1).

So the careful code in e.g. cbranchdi4 to not generate unimplemented comparisons is neutralized by generic code.

Do DImode comparisons really have to be asymmetric? I.e., could CC_NCV be removed?  I see that LT is apparently supported so why can't GT be too?
Comment 8 Mikael Pettersson 2011-06-12 21:33:30 UTC
I have a preliminary patch which creates a clone of *arm_cmpdi_insn that does a reverse comparison, via a new CC mode for must-be-reversed comparisons, and corresponding updates to arm_select_cc_mode and get_arm_condition_code.  It's the same transformation from eg (GT x y) to (LT y x) that cstoredi4 does, only later so it can handle problematic comparisons introduced by the middle-end.

This fixes the ICEs on the two test cases in this PR.  I'll do a full bootstrap and regtest as soon as my test machine is done with its current bootstrap and regtest cycle.

I'll send the FSF Yet Another Ping about my employer's copyright disclaimer first thing tomorrow.  They've had the papers since January or February...
Comment 9 rsandifo@gcc.gnu.org 2011-09-07 13:48:08 UTC
Author: rsandifo
Date: Wed Sep  7 13:48:03 2011
New Revision: 178636

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178636
	PR target/49030
	* config/arm/arm-protos.h (maybe_get_arm_condition_code): Declare.
	* config/arm/arm.c (maybe_get_arm_condition_code): New function,
	reusing the old code from get_arm_condition_code.  Return ARM_NV
	for invalid comparison codes.
	(get_arm_condition_code): Redefine in terms of
	* config/arm/predicates.md (arm_comparison_operator): Use

	PR target/49030
	* gcc.dg/torture/pr49030.c: New test.

Comment 10 Ryan Mansfield 2011-09-07 13:50:49 UTC
I am out of the office until September 19th. For emergencies please contact Fred Plante.
Comment 11 Georg-Johann Lay 2011-09-09 17:00:33 UTC
Author: gjl
Date: Fri Sep  9 17:00:26 2011
New Revision: 178736

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178736
	PR target/49030
	* gcc.dg/torture/pr49030.c: Run only if target int32plus.

Comment 12 rsandifo@gcc.gnu.org 2012-01-18 12:04:49 UTC
Fixed on trunk, and not marked as a regression.