Thread overview
[Issue 3681] New: internal error ../ztc/go.c 244
Jan 06, 2010
brien
Jan 07, 2010
Don
[Issue 3681] ICE(go.c): when function takes too long to optimize, only with -O.
Jan 12, 2010
Don
Feb 12, 2010
Kosmonaut
Nov 22, 2010
Don
Dec 27, 2010
Walter Bright
January 06, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3681

           Summary: internal error ../ztc/go.c 244
           Product: D
           Version: 1.054
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: brien@mailinator.com


--- Comment #0 from brien <brien@mailinator.com> 2010-01-06 12:05:19 PST ---
against 1.055

might be a regression of issue 2773

compiling with optimization crashes the compiler.


    public final class A {
        private this() {
            int i =0;
            int j = i +1;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;
            i = j * 15;
            j = i * 59;

        }
    }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 06, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3681


Lars T. Kyllingstad <bugzilla@kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@kyllingen.net


--- Comment #1 from Lars T. Kyllingstad <bugzilla@kyllingen.net> 2010-01-06 14:00:25 PST ---
This also fails with DMD 2.039.

Internal error: backend/go.c 244

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 07, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3681


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2010-01-07 00:02:12 PST ---
(In reply to comment #0)
> against 1.055
> 
> might be a regression of issue 2773

It isn't a regression. This is ancient -- it fails on DMD 0.175.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 12, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3681


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|ICE(go.c): Multiple         |ICE(go.c): when function
                   |assignments inside a        |takes too long to optimize,
                   |function, only with -O.     |only with -O.


--- Comment #3 from Don <clugdbug@yahoo.com.au> 2010-01-11 21:10:35 PST ---
The problem is simply that the optimiser needs too much time. The optimiser
loops for a maximum of 200 times, but to optimize this example requires 290
loops.
On the line it's faulting on:

-    assert(++iter < 200);
+    assert(++iter < 290);

However, there'll always be _some_ example where this happens. So a different approach is required. Maybe after 200 check that the number of elements is still decreasing on each pass through the loop; if it is, then just silently exit the loop without ICEing.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 12, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3681


Kosmonaut <Kosmonaut@tempinbox.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Kosmonaut@tempinbox.com


--- Comment #4 from Kosmonaut <Kosmonaut@tempinbox.com> 2010-02-12 11:42:15 PST ---
SVN Changeset: http://www.dsource.org/projects/dmd/changeset/376

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 22, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3681


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #5 from Don <clugdbug@yahoo.com.au> 2010-11-22 00:50:30 PST ---
CAUSE: This section of the optimiser can only remove one comma expression per
pass. So, the limit should be set based on the depth of comma expressions.
I don't know what the minimum iteration limit should be (the number of passes
for performing all other optimisations) -- when setting it to 10, as in the
code below, the test suite passes; a level of 5 is too low.

Note that the total limit used to be set to 80, before it was increased to 200. I am certain that the 80 was caused by comma expressions. Need to run this through the DMC test suite, to see what the minimum iteration limit should be.

----------


PATCH: Add this function to go.c. Actually it needs to used in the fix for bug 4379, as well. So maybe it should go into another file, or appear in a header file.


/*
   Return the maximum nesting of comma expressions in the elem tree.
   For example,  (((a, b) + c),d) * (e,f)  has comma depth 2.
*/
int commaDepth(elem *e)
{
    if ( EBIN(e))
    {
        int depth = (e->Eoper == OPcomma) ? 1 : 0;
        return depth + commaDepth(e->E1) + commaDepth(e->E2);
    }
    else if (EUNA(e))
        return commaDepth(e->E1);
    return 0;
}

Then, go.c, optfunc(), around line 230:

   if (localgot)
    {   // Initialize with:
        //      localgot = OPgot;
        elem *e = el_long(TYnptr, 0);
        e->Eoper = OPgot;
        e = el_bin(OPeq, TYnptr, el_var(localgot), e);
        startblock->Belem = el_combine(e, startblock->Belem);
    }

+    // Each pass through the loop can reduce only one level of comma
expression.
+    // The infinite loop check needs to take this into account.
+    int iterationLimit = 10;
+    for (b = startblock; b; b = b->Bnext)
+    {
+        if (!b->Belem)
+            continue;
+        int d = commaDepth(b->Belem);
+        if (d > iterationLimit)
+            iterationLimit = d;
+    }

    // Some functions can take enormous amounts of time to optimize.
    // We try to put a lid on it.
    starttime = clock();
    do
    {
        //printf("iter = %d\n", iter);
#if TX86
        //assert(++iter < 80);          /* infinite loop check           */
-        assert(++iter < 200);           /* infinite loop
+        assert(++iter < iterationLimit);           /* infinite loop check
     */
#else

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 27, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3681


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #6 from Walter Bright <bugzilla@digitalmars.com> 2010-12-26 23:46:39 PST ---
http://www.dsource.org/projects/dmd/changeset/821

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------