Bug 37991 - [4.4 Regression] excessive memory consumption - possible hang
Summary: [4.4 Regression] excessive memory consumption - possible hang
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P1 normal
Target Milestone: 4.4.0
Assignee: Richard Biener
URL:
Keywords: compile-time-hog, memory-hog
Depends on:
Blocks:
 
Reported: 2008-11-01 21:28 UTC by David Binderman
Modified: 2008-11-02 13:35 UTC (History)
3 users (show)

See Also:
Host:
Target: i?86-*-*, x86_64-*-*
Build:
Known to work: 4.3.2
Known to fail:
Last reconfirmed: 2008-11-02 11:27:05


Attachments
C++ source code (41.94 KB, text/plain)
2008-11-01 21:28 UTC, David Binderman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2008-11-01 21:28:00 UTC
I just tried to compile the attached C++ source code with both
gcc 4.3.1 and gcc 4.4.0 snapshot 20081031.

gcc 431 took less than one second and consumed a trivial amount
of virtual memory.

gcc 440 snapshot 20081031 took over 90 seconds on an idle machine,
and consumed over 11 Gig of virtual memory before running out of
virtual memory.

In my opinion, 11 Gig of memory is an excessive amount of memory to use.
I suspect the compiler is looping without doing any productive work.

Preprocessed source code attached. Flag -O2 required.
Comment 1 David Binderman 2008-11-01 21:28:50 UTC
Created attachment 16611 [details]
C++ source code
Comment 2 Richard Biener 2008-11-02 10:42:12 UTC
Confirmed.  We seem to be very slowly eating all of memory during processing
a single SCC in FRE - which means iteration doesn't converge.
Comment 3 Richard Biener 2008-11-02 10:58:50 UTC
Reducing.
Comment 4 Richard Biener 2008-11-02 11:27:05 UTC
The following fails this way with plain -O.  The key is the typedef - if you
replace the use of UInt32 with unsinged int the testcase succeeds.  Mine.

typedef unsigned int UInt32;
int Read(unsigned int *processedSize);
void FindAndReadSignature(void)
{   
    unsigned int numPrevBytes = 31;
    for (;;)
      {
        unsigned int numReadBytes = (1 << 16) - numPrevBytes;
        unsigned int processedSize;
        int __result__ = Read(&processedSize);
        unsigned int numBytesInBuffer = numPrevBytes + processedSize;
        UInt32 numTests = numBytesInBuffer - 31;
        for (unsigned int pos = 0; pos < numTests; pos++)
          ;
        numPrevBytes = numBytesInBuffer - numTests;
      }
}
Comment 5 Richard Biener 2008-11-02 12:04:08 UTC
More reduced:

typedef int Int32;
void use_it(int);
void FindAndReadSignature(int processedSize)
{
    int numPrevBytes = 1;
    for (;;)
      {
        int numBytesInBuffer = numPrevBytes + processedSize;
        Int32 numTests = numBytesInBuffer - 1;
        use_it (numTests);
        numPrevBytes = numBytesInBuffer - numTests;
      }
}

to not oscillate we rely on numTests _not_ be varying.  It happens to be
with the typedef as we forget to strip useless conversions.  Otherwise
we oscillate numPrevBytes (loop entry vs. back edge) between 1 and varying.

Which may hint at that the speedup brought up by Danny (not processing a
use further if it got varying) is even a correctness thing...

I have a patch for this particular case.
Comment 6 Richard Biener 2008-11-02 13:35:41 UTC
Fixed.
Comment 7 Richard Biener 2008-11-02 13:36:23 UTC
Subject: Bug 37991

Author: rguenth
Date: Sun Nov  2 13:34:58 2008
New Revision: 141532

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141532
Log:
2008-11-02  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/37991
	* tree-ssa-sccvn.h (copy_vuses_from_stmt): Remove.
	* tree-ssa-sccvn.c (copy_vuses_from_stmt): Make static.
	(set_ssa_val_to): Print if the value changed.
	(simplify_binary_expression): Strip useless conversions.

	* gcc.c-torture/compile/pr37991.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/pr37991.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-sccvn.c
    trunk/gcc/tree-ssa-sccvn.h

Comment 8 Daniel Berlin 2008-11-02 20:53:41 UTC
Subject: Re:  [4.4 Regression] excessive memory consumption - possible hang

On Sun, Nov 2, 2008 at 7:04 AM, rguenth at gcc dot gnu dot org
<gcc-bugzilla@gcc.gnu.org> wrote:
>
>
> ------- Comment #5 from rguenth at gcc dot gnu dot org  2008-11-02 12:04 -------
> More reduced:
>
> typedef int Int32;
> void use_it(int);
> void FindAndReadSignature(int processedSize)
> {
>    int numPrevBytes = 1;
>    for (;;)
>      {
>        int numBytesInBuffer = numPrevBytes + processedSize;
>        Int32 numTests = numBytesInBuffer - 1;
>        use_it (numTests);
>        numPrevBytes = numBytesInBuffer - numTests;
>      }
> }
>
> to not oscillate we rely on numTests _not_ be varying.  It happens to be
> with the typedef as we forget to strip useless conversions.  Otherwise
> we oscillate numPrevBytes (loop entry vs. back edge) between 1 and varying.
>
> Which may hint at that the speedup brought up by Danny (not processing a
> use further if it got varying) is even a correctness thing...


Things should never go up the lattice :)