User account creation filtered due to spam.

Bug 78911 - [5/6 Regression] Infinite loop at -O2/O3 optimization levels while trying to compile server.c from Wine-2.0-rc2
Summary: [5/6 Regression] Infinite loop at -O2/O3 optimization levels while trying to ...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 6.2.1
: P2 normal
Target Milestone: 5.5
Assignee: Bernd Schmidt
URL: https://dl.winehq.org/wine/source/2.0...
Keywords: compile-time-hog, ra
Depends on:
Blocks:
 
Reported: 2016-12-23 10:46 UTC by Artem S. Tashkinov
Modified: 2017-06-20 21:34 UTC (History)
6 users (show)

See Also:
Host: x86_64-redhat-linux
Target: i686 (-march=pentium-m -m32)
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-12-23 00:00:00


Attachments
Sources (105.50 KB, application/x-bzip)
2016-12-23 10:46 UTC, Artem S. Tashkinov
Details
head -n700000 tc.i.274r.reload (581.74 KB, application/x-bzip)
2016-12-23 11:50 UTC, Martin Liška
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Artem S. Tashkinov 2016-12-23 10:46:15 UTC
Created attachment 40408 [details]
Sources

gcc -c -o server.o server.c -I. -I../../include -D__WINESRC__ -D_NTSYSTEM_ -D_REENTRANT -fPIC -Wall \
  -pipe -fno-strict-aliasing -Wdeclaration-after-statement -Wempty-body -Wignored-qualifiers \
  -Wshift-overflow=2 -Wstrict-prototypes -Wtype-limits -Wunused-but-set-parameter -Wvla \
  -Wwrite-strings -Wpointer-arith -Wlogical-op -fno-omit-frame-pointer -O2 -march=pentium-m -m32 -pipe -D__i386__

gcc --version
gcc (GCC) 6.2.1 20160916 (Red Hat 6.2.1-2)

gcc -c -o server.o server.c -I. -I../../include -D__WINESRC__ -D_NTSYSTEM_ -D_REENTRANT -fPIC -Wall \
>   -pipe -fno-strict-aliasing -Wdeclaration-after-statement -Wempty-body -Wignored-qualifiers \
>   -Wshift-overflow=2 -Wstrict-prototypes -Wtype-limits -Wunused-but-set-parameter -Wvla \
>   -Wwrite-strings -Wpointer-arith -Wlogical-op -fno-omit-frame-pointer -O2 -march=pentium-m -m32 -pipe -D__i386__ -v -save-temps

gcc: warning: -pipe ignored because -save-temps specified
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --disable-libgcj --with-isl --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 6.2.1 20160916 (Red Hat 6.2.1-2) (GCC) 
COLLECT_GCC_OPTIONS='-c' '-o' 'server.o' '-I' '.' '-I' '../../include' '-D' '__WINESRC__' '-D' '_NTSYSTEM_' '-D' '_REENTRANT' '-fPIC' '-Wall' '-pipe' '-fno-strict-aliasing' '-Wdeclaration-after-statement' '-Wempty-body' '-Wignored-qualifiers' '-Wshift-overflow=2' '-Wstrict-prototypes' '-Wtype-limits' '-Wunused-but-set-parameter' '-Wvla' '-Wwrite-strings' '-Wpointer-arith' '-Wlogical-op' '-fno-omit-frame-pointer' '-O2' '-march=pentium-m' '-m32' '-pipe' '-D' '__i386__' '-v' '-save-temps'
 /usr/libexec/gcc/x86_64-redhat-linux/6.2.1/cc1 -E -quiet -v -I . -I ../../include -imultilib 32 -D __WINESRC__ -D _NTSYSTEM_ -D _REENTRANT -D __i386__ server.c -march=pentium-m -m32 -Wall -Wdeclaration-after-statement -Wempty-body -Wignored-qualifiers -Wshift-overflow=2 -Wstrict-prototypes -Wtype-limits -Wunused-but-set-parameter -Wvla -Wwrite-strings -Wpointer-arith -Wlogical-op -fPIC -fno-strict-aliasing -fno-omit-frame-pointer -O2 -fpch-preprocess -o server.i
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/6.2.1/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/6.2.1/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 .
 ../../include
 /usr/lib/gcc/x86_64-redhat-linux/6.2.1/include
 /usr/local/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-c' '-o' 'server.o' '-I' '.' '-I' '../../include' '-D' '__WINESRC__' '-D' '_NTSYSTEM_' '-D' '_REENTRANT' '-fPIC' '-Wall' '-pipe' '-fno-strict-aliasing' '-Wdeclaration-after-statement' '-Wempty-body' '-Wignored-qualifiers' '-Wshift-overflow=2' '-Wstrict-prototypes' '-Wtype-limits' '-Wunused-but-set-parameter' '-Wvla' '-Wwrite-strings' '-Wpointer-arith' '-Wlogical-op' '-fno-omit-frame-pointer' '-O2' '-march=pentium-m' '-m32' '-pipe' '-D' '__i386__' '-v' '-save-temps'
 /usr/libexec/gcc/x86_64-redhat-linux/6.2.1/cc1 -fpreprocessed server.i -quiet -dumpbase server.c -march=pentium-m -m32 -auxbase-strip server.o -O2 -Wall -Wdeclaration-after-statement -Wempty-body -Wignored-qualifiers -Wshift-overflow=2 -Wstrict-prototypes -Wtype-limits -Wunused-but-set-parameter -Wvla -Wwrite-strings -Wpointer-arith -Wlogical-op -version -fPIC -fno-strict-aliasing -fno-omit-frame-pointer -o server.s
GNU C11 (GCC) version 6.2.1 20160916 (Red Hat 6.2.1-2) (x86_64-redhat-linux)
	compiled by GNU C version 6.2.1 20160916 (Red Hat 6.2.1-2), GMP version 6.1.1, MPFR version 3.1.4, MPC version 1.0.2, isl version 0.14 or 0.13
warning: MPFR header version 3.1.4 differs from library version 3.1.5.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C11 (GCC) version 6.2.1 20160916 (Red Hat 6.2.1-2) (x86_64-redhat-linux)
	compiled by GNU C version 6.2.1 20160916 (Red Hat 6.2.1-2), GMP version 6.1.1, MPFR version 3.1.4, MPC version 1.0.2, isl version 0.14 or 0.13
warning: MPFR header version 3.1.4 differs from library version 3.1.5.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: cf9b61d8c1933eb6edbda3ca13701096

At this point the compiler hangs (infinite 100% CPU usage).
Comment 1 Artem S. Tashkinov 2016-12-23 10:49:49 UTC
Update:

various -march variants have no effect.

-O3 : still hangs

-Os : compiles
Comment 2 Martin Liška 2016-12-23 11:28:20 UTC
Confirmed, started with r221983. I'm reducing the test-case.
Comment 3 Markus Trippelsdorf 2016-12-23 11:30:25 UTC
Spins in lra:

  32.64%  cc1    [.] lra_create_live_ranges_1
  10.52%  cc1    [.] lra_assign
   7.57%  cc1    [.] bitmap_set_bit

Trunk works fine for me.
Comment 4 Martin Liška 2016-12-23 11:43:44 UTC
The mentioned revision is probably not probably the culprit.
Reduced test-case:

$ cat tc.i
a, b, d, e;
*c;
static interlocked_cmpxchg64 (long long *p1)
{
  __sync_val_compare_and_swap (p1, b, a);
}
get_cached_fd ()
{
  if (!c)
    return;
  e = interlocked_cmpxchg64 (&c[d]);
}

$ timeout 10 gcc -O3 -march=pentium-m -m32 -c  -fPIC -Wall   -fno-strict-aliasing -fno-omit-frame-pointer tc.i
[triggers time-out]

Can you see it also on trunk?
Comment 5 Markus Trippelsdorf 2016-12-23 11:46:46 UTC
(In reply to Martin Liška from comment #4)
> Can you see it also on trunk?

Yes, but only with -O3.
Comment 6 Martin Liška 2016-12-23 11:50:28 UTC
Created attachment 40409 [details]
head -n700000 tc.i.274r.reload

So the problem is older than r221983.
Comment 7 Jakub Jelinek 2017-01-06 15:36:05 UTC
Slightly cleaned up testcase:

/* PR rtl-optimization/78911 */
/* { dg-do compile } */
/* { dg-options "-O3 -fPIC -fno-strict-aliasing -fno-omit-frame-pointer" } */
/* { dg-additional-options "-fPIC" { target fpic } } */
/* { dg-additional-options "-march=pentium-m" { target ia32 } } */

int a, b, d, e;
long long *c;

static int
foo (long long *x)
{
  return __sync_val_compare_and_swap (x, b, a);
}

void
bar (void)
{
  if (!c)
    return;
  e = foo (&c[d]);
}

Started hanging with r216281.
Comment 8 Uroš Bizjak 2017-01-06 17:16:45 UTC
(In reply to Martin Liška from comment #6)
> Created attachment 40409 [details]
> head -n700000 tc.i.274r.reload
> 
> So the problem is older than r221983.

Why do you think so? Reverting r221983 one-liner, introduced in PR65710 as a performance fix for earlier patch, allows me to compile the testcase.

(In reply to Jakub Jelinek from comment #7)

> Started hanging with r216281.

Referred commit allowed atomic_compare_and_swapdi_doubleword pattern to directly use %ebx, which was not allowed before pseudo PIC reg was introduced. Mentioned pattern pushes i686 register pressure to the limit, it is somehow problematic for RA to handle, but RA managed to do correct reg allocation up to r221983.
Comment 9 Jakub Jelinek 2017-01-06 19:54:49 UTC
At least for me it hangs already in that r216281:
timeout 20 /opt/notnfs/gcc-bisect/obj/gcc/cc1.216281 -quiet -O3 -march=pentium-m -m32 -fPIC -fno-strict-aliasing -fno-omit-frame-pointer pr78911.c; echo $?
124
-bash-4.3$ timeout 20 /opt/notnfs/gcc-bisect/obj/gcc/cc1.216280 -quiet -O3 -march=pentium-m -m32 -fPIC -fno-strict-aliasing -fno-omit-frame-pointer pr78911.c; echo $?
0
(the latter is instant, fraction of a second).
Comment 10 Uroš Bizjak 2017-01-07 09:15:33 UTC
(In reply to Jakub Jelinek from comment #9)
> At least for me it hangs already in that r216281:

I don't have PR at hand, but pLease note that there were some problems with this pattern in the past, fixed in the RA in the meantime. With pseudo-PIC, there is enough registers available for RA, even with allocated frame-pointer.
Comment 11 Bernd Schmidt 2017-03-02 02:35:09 UTC
Investigating (but not entirely sure yet I'm getting somewhere).
Comment 12 Jakub Jelinek 2017-03-02 07:32:13 UTC
Testcase for likely the same bug, at least hang starts at r221983.

-fPIC -O2 -m32 -march=i686 -fno-omit-frame-pointer rh1406093.i

long long *a, *b, c;
int d, e;
int baz (void);

static inline long long
foo (long long *x)
{
  return __sync_val_compare_and_swap (x, 0, 0);
}

void
bar ()
{
  int f = baz ();
  c = foo (&a[f]);
  if (c)
    e = d;
  a = b;
}
Comment 13 Bernd Schmidt 2017-03-10 21:17:45 UTC
Author: bernds
Date: Fri Mar 10 21:17:13 2017
New Revision: 246059

URL: https://gcc.gnu.org/viewcvs?rev=246059&root=gcc&view=rev
Log:
	PR rtl-optimization/78911
	* lra-assigns.c (must_not_spill_p): New function.
	(spill_for): Use it.

	PR rtl-optimization/78911
	* gcc.target/i386/pr78911-1.c: New test.
	* gcc.target/i386/pr78911-2.c: New test.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr78911-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr78911-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/lra-assigns.c
    trunk/gcc/testsuite/ChangeLog
Comment 14 Bernd Schmidt 2017-03-10 21:31:26 UTC
Fixed on trunk.
Comment 15 Artem S. Tashkinov 2017-06-20 21:34:01 UTC
Strangely, this bug is still reproducible with GCC 6.3.1 and Wine 2.10.