Bug 65693 - [4.8/4.9 Regression] ICE in assign_by_spills, at lra-assigns.c:1419
Summary: [4.8/4.9 Regression] ICE in assign_by_spills, at lra-assigns.c:1419
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 5.0
: P2 normal
Target Milestone: 4.8.5
Assignee: Not yet assigned to anyone
URL:
Keywords: ra
Depends on:
Blocks:
 
Reported: 2015-04-08 09:33 UTC by Gianfranco
Modified: 2015-04-09 16:08 UTC (History)
6 users (show)

See Also:
Host:
Target: x86_64-*-*, i?86-*-*
Build:
Known to work: 4.3.4, 4.5.4, 5.0
Known to fail: 4.6.4
Last reconfirmed: 2015-04-08 00:00:00


Attachments
snip of the build log (26.39 KB, text/plain)
2015-04-08 09:33 UTC, Gianfranco
Details
log with -Wall -Wextra -fno-strict-aliasing -fwrapv (18.17 KB, text/plain)
2015-04-08 09:36 UTC, Gianfranco
Details
preprocessed source (17.64 KB, application/octet-stream)
2015-04-08 09:42 UTC, Gianfranco
Details
gcc5-pr65693.patch (968 bytes, patch)
2015-04-08 15:55 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gianfranco 2015-04-08 09:33:49 UTC
Created attachment 35251 [details]
snip of the build log

I can't build anymore virtualbox with gcc 5-20150404-1 in experimental (medium)  (debian experimental)

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 5-20150404-1' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=c++98 --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --with-arch-32=i586 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=yes --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.0.0 20150404 (experimental) [trunk revision 221867] (Debian 5-20150404-1) 


attaching the build log, the build log2 with -Wall -Wextra -fno-strict-aliasing and the preprocessed source
Comment 1 Gianfranco 2015-04-08 09:36:21 UTC
Created attachment 35252 [details]
log with -Wall -Wextra -fno-strict-aliasing -fwrapv
Comment 2 Gianfranco 2015-04-08 09:42:32 UTC
Created attachment 35253 [details]
preprocessed source
Comment 3 Markus Trippelsdorf 2015-04-08 09:48:28 UTC
markus@x4 tmp % cat t.ii
int a;
unsigned b;
void
VBoxNsxpXPTC_InvokeByIndex ()
{
  unsigned long *c = (unsigned long *) __builtin_alloca (b);
  a = *c;
  register int d asm("rdx")
      = ((int (*) (int, int, int, int, int, int)) 0)(0, 0, d, 0, 0, 0);
}

markus@x4 tmp % g++ -c t.ii
t.ii: In function ‘void VBoxNsxpXPTC_InvokeByIndex()’:
t.ii:10:1: error: unable to find a register to spill
 }
 ^
t.ii:10:1: error: this is the insn:
(insn 10 37 11 2 (parallel [
            (set (reg:DI 97)
                (udiv:DI (reg:DI 95)
                    (reg:DI 107)))
            (set (reg:DI 108 [98])
                (umod:DI (reg:DI 95)
                    (reg:DI 107)))
            (clobber (reg:CC 17 flags))
        ]) t.ii:6 352 {*udivmoddi4}
     (expr_list:REG_UNUSED (reg:DI 108 [98])
        (expr_list:REG_DEAD (reg:DI 107)
            (expr_list:REG_DEAD (reg:DI 95)
                (expr_list:REG_UNUSED (reg:CC 17 flags)
                    (nil))))))
t.ii:10: confused by earlier errors, bailing out
Comment 4 Marek Polacek 2015-04-08 09:55:25 UTC
I don't think this is a 5 Regression, even 4.6 ICEs for me.
Comment 5 Markus Trippelsdorf 2015-04-08 10:07:54 UTC
Well, this testcase only ICEs with gcc-5:

markus@x4 tmp % < foo.ii
int a, b;
unsigned c;
static void
invoke_copy_to_stack (unsigned long *p1, int, int)
{
  for (; b;)
    if (a)
      *p1 = 0;
}

void
VBoxNsxpXPTC_InvokeByIndex ()
{
  unsigned long *d = (unsigned long *) __builtin_alloca (c);
  invoke_copy_to_stack (d, 0, 0);
  register int e asm("rdx")
      = ((int (*) (int, int, int, int, int, int)) 0)(0, 0, e, 0, 0, 0);
}

markus@x4 tmp % g++ -O -c foo.ii
foo.ii: In function ‘void VBoxNsxpXPTC_InvokeByIndex()’:
foo.ii:18:1: error: unable to find a register to spill
 }
 ^
foo.ii:18:1: error: this is the insn:
(insn 9 8 10 2 (parallel [
            (set (reg:DI 98)
                (udiv:DI (reg:DI 96)
                    (reg:DI 106)))
            (set (reg:DI 109 [99])
                (umod:DI (reg:DI 96)
                    (reg:DI 106)))
            (clobber (reg:CC 17 flags))
        ]) foo.ii:14 352 {*udivmoddi4}
     (expr_list:REG_UNUSED (reg:DI 109 [99])
        (expr_list:REG_DEAD (reg:DI 106)
            (expr_list:REG_DEAD (reg:DI 96)
                (expr_list:REG_UNUSED (reg:CC 17 flags)
                    (nil))))))
foo.ii:18: confused by earlier errors, bailing out
Comment 6 Richard Biener 2015-04-08 10:11:25 UTC
4.3 works for me so does 4.5.
Comment 7 Uroš Bizjak 2015-04-08 10:13:37 UTC
gcc-4.9 combines udivmoddi4 to :

(insn 30 5 8 2 (set (reg:DI 103)
        (const_int 16 [0x10])) pr65693.ii:6 -1
     (nil))

[...]

(insn 9 8 10 2 (parallel [
            (set (reg:DI 94)
                (udiv:DI (reg:DI 92)
                    (reg:DI 103)))
            (set (reg:DI 95)
                (umod:DI (reg:DI 92)
                    (reg:DI 103)))
            (clobber (reg:CC 17 flags))
        ]) pr65693.ii:6 348 {*udivmoddi4}
     (expr_list:REG_DEAD (reg:DI 103)
        (expr_list:REG_DEAD (reg:DI 92)
            (expr_list:REG_UNUSED (reg:DI 95)
                (expr_list:REG_UNUSED (reg:CC 17 flags)
                    (nil))))))


Trying 30 -> 9:

...

Successfully matched this instruction:
(set (reg:DI 94)
    (lshiftrt:DI (reg:DI 92)
        (const_int 4 [0x4])))

For some reason gcc-5 doesn't do this conversion anymore.
Comment 8 Gianfranco 2015-04-08 10:17:19 UTC
Nope, I can build on debian (I'm the maintainer BTW) with 4.9 successfully.

https://buildd.debian.org/status/fetch.php?pkg=virtualbox&arch=amd64&ver=4.3.26-dfsg-1&stamp=1426696248

for now I forced gcc-4.9 as a gcc version and the build completes with no problems.

This is why I think this is a gcc-5.0 specific regression.

Also gcc 4.8 and 4.7 are fine (I maintain a backport on ubuntu too, and they all build correctly).

This is a snapshot of virtualbox 5.0.0_BETA1, but the ICE occurs with virtualbox 4.3.26 and older releases (but *only* with gcc-5)
Comment 9 Markus Trippelsdorf 2015-04-08 11:09:26 UTC
Started with r218248.
Comment 10 Gianfranco 2015-04-08 11:19:05 UTC
Hi @Markus, I'm *really* impressed about your efficiency.

I reported the progresses on the vbox official mail list, thanks!
Comment 11 Segher Boessenkool 2015-04-08 13:48:47 UTC
I see GCC not trying to throw away the useless arm of the parallel,
just as comment 7 mentions.  I wonder why that is, investigating.

This isn't the root cause; it is just exposing a problem in the RA :-(
Comment 12 Jakub Jelinek 2015-04-08 14:27:51 UTC
Well, the RA issue is hard to deal with, there is a local register var that uses a register some instruction needs while the local register is live.
Anyway, this alloca/VLA division issue is what I meant to fix with PR65220, but here unfortunately the RTL cprop isn't performed because the function has a single basic block and for some reason RTL cprop doesn't perform even the local cprop subpass then.
And, at combine time, combiner attempts to simplify the insn, so the *udivmod<mode>4_pow2 pattern no longer matches.
One possibility to fix this would be to add *udivmod<mode>4_pow2_1 pattern that would just have the lshiftrt and and instructions in PARALLEL until reload, then split them.
Comment 13 Jakub Jelinek 2015-04-08 15:55:58 UTC
Created attachment 35261 [details]
gcc5-pr65693.patch

Untested fix.
Comment 14 Segher Boessenkool 2015-04-08 21:43:02 UTC
I sent a patch for the combine issue, http://gcc.gnu.org/ml/gcc-patches/2015-04/msg00359.html .
Comment 15 Segher Boessenkool 2015-04-08 22:52:55 UTC
Author: segher
Date: Wed Apr  8 22:52:24 2015
New Revision: 221937

URL: https://gcc.gnu.org/viewcvs?rev=221937&root=gcc&view=rev
Log:
	PR rtl-optimization/65693
	* combine.c (is_parallel_of_n_reg_sets): Change first argument
	from an rtx_insn * to an rtx.
	(try_combine): Adjust both callers.  Use it once more.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/combine.c
Comment 16 Jakub Jelinek 2015-04-09 07:29:26 UTC
Author: jakub
Date: Thu Apr  9 07:28:54 2015
New Revision: 221942

URL: https://gcc.gnu.org/viewcvs?rev=221942&root=gcc&view=rev
Log:
	PR target/65693
	* config/i386/i386.md (*udivmod<mode>4_pow2): Allow
	any pow2 integer in between 2 and 0x80000000U inclusive.

	* gcc.target/i386/pr65693.c: New test.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr65693.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.md
    trunk/gcc/testsuite/ChangeLog
Comment 17 Segher Boessenkool 2015-04-09 14:37:46 UTC
Author: segher
Date: Thu Apr  9 14:37:14 2015
New Revision: 221951

URL: https://gcc.gnu.org/viewcvs?rev=221951&root=gcc&view=rev
Log:
	PR rtl-optimization/65693
	* combine.c (is_parallel_of_n_reg_sets): Move outside of
	#ifndef HAVE_cc0.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/combine.c
Comment 18 Jakub Jelinek 2015-04-09 15:52:26 UTC
Fixed on the trunk so far.
Comment 19 Gianfranco 2015-04-09 16:08:50 UTC
I tested a build with the patch https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=221937 and the build seems to have been successfully completed (I got some pedantic errors, but nothing spills related)

thanks a lot to everybody for the support!