Bug 67954 - [5 / 6 Regression] internal compiler error: in patch_jump_insn, at cfgrtl.c:1303
Summary: [5 / 6 Regression] internal compiler error: in patch_jump_insn, at cfgrtl.c:1303
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 5.1.0
: P3 normal
Target Milestone: 5.3
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2015-10-13 13:27 UTC by Dmitry Eremin-Solenikov
Modified: 2015-11-26 22:15 UTC (History)
3 users (show)

See Also:
Host:
Target: arm*
Build:
Known to work: 4.8.0
Known to fail: 5.1.0, 5.2.0, 6.0
Last reconfirmed: 2015-11-19 00:00:00


Attachments
Preprocessed source file (18.59 KB, text/plain)
2015-10-13 13:27 UTC, Dmitry Eremin-Solenikov
Details
reduced testcase (966 bytes, text/plain)
2015-11-19 13:00 UTC, Ramana Radhakrishnan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Eremin-Solenikov 2015-10-13 13:27:46 UTC
Created attachment 36501 [details]
Preprocessed source file

Since https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=210824 GCC fails with ICE when generating ARM Thumb1 code:

/tmp/test.i: In function 'ubidi_writeReordered_55':
/tmp/test.i:4748:1: internal compiler error: in patch_jump_insn, at cfgrtl.c:1303
 }
 ^
0x63700e patch_jump_insn
        ../../gcc/gcc/cfgrtl.c:1303
0x63715b redirect_branch_edge
        ../../gcc/gcc/cfgrtl.c:1329
0x6376e2 rtl_redirect_edge_and_branch
        ../../gcc/gcc/cfgrtl.c:1462
0x629889 redirect_edge_and_branch(edge_def*, basic_block_def*)
        ../../gcc/gcc/cfghooks.c:376
0xd0be1d try_forward_edges
        ../../gcc/gcc/cfgcleanup.c:621
0xd0be1d try_optimize_cfg
        ../../gcc/gcc/cfgcleanup.c:2835
0xd0be1d cleanup_cfg(int)
        ../../gcc/gcc/cfgcleanup.c:3049
0xd0d318 execute
        ../../gcc/gcc/cfgcleanup.c:3178


The following commands fail:

* gcc -march=armv4t -mthumb /tmp/test.i -S -o /tmp/test.o  -O1 -fcrossjumping
* gcc -march=armv5te -mthumb /tmp/test.i -S -o /tmp/test.o  -O1 -fcrossjumping
* gcc -march=armv6 -mthumb /tmp/test.i -S -o /tmp/test.o  -O1 -fcrossjumping

The following work:
* gcc -march=armv6t2 -mthumb /tmp/test.i -S -o /tmp/test.o  -O1 -fcrossjumping
* gcc -march=armv5te -marm /tmp/test.i -S -o /tmp/test.o  -O1 -fcrossjumping
* gcc -march=armv5te -mthumb /tmp/test.i -S -o /tmp/test.o  -O1

The log was produced using clear gcc from gcc-5_1_0-release tag.

The following configure options were passed to gcc:

../gcc/configure --build=x86_64-linux                  --host=x86_64-linux             --target=arm-linux-gnueabi                                 --enable-languages=c --enable-checking=all --disable-nls
Comment 1 Richard Biener 2015-11-18 12:12:00 UTC
Please try a more recent snapshot from the GCC 5 branch.
Comment 2 Ramana Radhakrishnan 2015-11-19 12:55:57 UTC
trunk and 5.2.1 20151108 fails with the command line options 

-march=armv4t -mthumb -mfloat-abi=soft -O2 and the testcase. 

reducing.
Comment 3 Ramana Radhakrishnan 2015-11-19 13:00:40 UTC
Created attachment 36771 [details]
reduced testcase

reduced testcase
Comment 4 Jakub Jelinek 2015-11-24 14:22:59 UTC
Sounds like a RA issue to me.
In *.ira we have:
(jump_insn 175 174 176 26 (parallel [
            (set (pc)
                (if_then_else (lt (plus:SI (reg/v:SI 134 [ runCount ])
                            (const_int -1 [0xffffffffffffffff]))
                        (const_int 0 [0]))
                    (label_ref 105)
                    (pc)))
            (set (reg/v:SI 152 [ runCount ])
                (plus:SI (reg/v:SI 134 [ runCount ])
                    (const_int -1 [0xffffffffffffffff])))
            (clobber (scratch:SI))
        ]) pr67954.i:89 759 {*addsi3_cbranch}
     (expr_list:REG_DEAD (reg/v:SI 134 [ runCount ])
        (int_list:REG_BR_PROB 900 (nil)))
 -> 105)
and then in *.reload we have:
Choosing alt 4 in insn 175:  (0) *?m  (1) &l  (2) 1  (3) lIJ {*addsi3_cbranch}
...
Choosing alt 1 in insn 175:  (0) l  (1) X  (2) l  (3) lL {*addsi3_cbranch}
...
Choosing alt 1 in insn 175:  (0) l  (1) X  (2) l  (3) lL {*addsi3_cbranch}
...
Choosing alt 1 in insn 175:  (0) l  (1) X  (2) l  (3) lL {*addsi3_cbranch}
...
(jump_insn 175 548 176 26 (parallel [
            (set (pc)
                (if_then_else (lt (plus:SI (reg:SI 3 r3 [374])
                            (const_int -1 [0xffffffffffffffff]))
                        (const_int 0 [0]))
                    (label_ref 105)
                    (pc)))
            (set (reg/v:SI 2 r2 [orig:152 runCount ] [152])
                (plus:SI (reg:SI 3 r3 [374])
                    (const_int -1 [0xffffffffffffffff])))
            (clobber (mem/c:SI (reg:SI 2 r2 [437]) [6 %sfp+-32 S4 A32]))
        ]) pr67954.i:89 759 {*addsi3_cbranch}
     (int_list:REG_BR_PROB 900 (nil))
 -> 105)

The pattern has
   (clobber (match_scratch:SI 1 "=X,X,l,l,&l,&l"))]
If LRA really chooses the alt 1, then the match_scratch has =X constraint, but I would expect that it would not leave in complete garbage like the memory dereference that doesn't pass scratch_operand.  Vlad?

Note I could only reproduce this on the 5 branch.
Comment 5 Vladimir Makarov 2015-11-25 17:57:47 UTC
Author: vmakarov
Date: Wed Nov 25 17:57:15 2015
New Revision: 230893

URL: https://gcc.gnu.org/viewcvs?rev=230893&root=gcc&view=rev
Log:
2015-11-25  Vladimir Makarov  <vmakarov@redhat.com>

	PR rtl-optimization/67954
	* lra-constraints.c (curr_insn_transform): Add check on scratch
	pseudo when change class to NO_REGS.  Add an assert.


Modified:
    branches/gcc-5-branch/gcc/ChangeLog
    branches/gcc-5-branch/gcc/lra-constraints.c
Comment 6 Vladimir Makarov 2015-11-25 17:59:06 UTC
Author: vmakarov
Date: Wed Nov 25 17:58:35 2015
New Revision: 230894

URL: https://gcc.gnu.org/viewcvs?rev=230894&root=gcc&view=rev
Log:
2015-11-25  Vladimir Makarov  <vmakarov@redhat.com>

	PR rtl-optimization/67954
	* lra-constraints.c (curr_insn_transform): Add check on scratch
	pseudo when change class to NO_REGS.  Add an assert.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/lra-constraints.c
Comment 7 Vladimir Makarov 2015-11-25 18:03:37 UTC
  The problem occurred in rare cases when a pseudo created from a scratch was reloaded and assigned to reg and memory back again.  The new reload pseudo loses "created from clobber" mark and occurs more once in insns.
Comment 8 Jakub Jelinek 2015-11-25 18:04:26 UTC
Assuming fixed for 5.3+.
Comment 9 Dmitry Eremin-Solenikov 2015-11-26 02:02:27 UTC
This also needs to be applied to the 4.9 branch -- it also contains an offending commit.
Comment 10 Vladimir Makarov 2015-11-26 22:14:07 UTC
Author: vmakarov
Date: Thu Nov 26 22:13:36 2015
New Revision: 230986

URL: https://gcc.gnu.org/viewcvs?rev=230986&root=gcc&view=rev
Log:
2015-11-25  Vladimir Makarov  <vmakarov@redhat.com>

	PR rtl-optimization/67954
	* lra-constraints.c (curr_insn_transform): Add check on scratch
	pseudo when change class to NO_REGS.  Add an assert.


Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/lra-constraints.c
Comment 11 Vladimir Makarov 2015-11-26 22:15:28 UTC
(In reply to Dmitry Eremin-Solenikov from comment #9)
> This also needs to be applied to the 4.9 branch -- it also contains an
> offending commit.

Thanks for the remainder.  I've just committed the patch into gcc-4.9 branch too.