Issue 9: Compiler output misses labels after tests
Status:  Fixed
Owner:
Closed:  Oct 2011
Project Member Reported by ejrh00@gmail.com, Oct 17, 2011
mandelbrot.e doesn't compile properly.  The problem is this bit of output:

   ...
   L129:
   #Vertex 70 assign $t11 = y
       movl %ecx, %ebx
   ...
   #Vertex 15 test $t9 != $t30
       cmpl -104(%ebp), %ebx
       jnz L141
       jmp L129

   # Should be L141:
   #Vertex 82 assign $n58x = y
       movl %ecx, %eax
   ...

Every vertex that gets output has a label e.g. Vertex 70 gets the label "L129:" which is printed just before it.  That's so that if you try to jump to that vertex from anywhere else (e.g. in vertex 15), it can find where it's jumping to.

The thing is that that most labels never get jumped to.  To avoid bloating the output it tries not to print the label when the only thing that leads into it was immediately preceding it in the output.

In the case of vertex 82, it wasn't printing the label, because the only way to get to 82 was from 15, which has just been printed.  Unfortunately... vertex 15 is a test vertex with some complicated conditional jumps.  It gets to the next vertex by jumping early if the condition is true, otherwise falling through and jumping off somewhere else.

So in this case, although its predecessor is immediately prior to it, vertex 82 still needs a label so that that predecessor's jump can find it.

Solution A is to force labels to be printed after tests like this.

Solution B would be to detect this case and emit the test as something like:

       cmpl -104(%ebp), %ebx
       jz L129
       # Else fall through to next vertex

In theory sometimes one way of testing is faster than another, so a good compiler (which mine isn't) would have heuristics for that and rearrange tests for optimality.

Solution A should be implemented somewhere in emit-graph.c.

Oct 19, 2011
Project Member #1 ejrh00@gmail.com
It's not repeatable.  After reinstalling the OS the compile does not appear to have missed any labels.  It's very annoying.  And it's probably due to using pointers as keys in hash tables (perhaps we should just stop doing that full stop).

Oct 26, 2011
Project Member #2 ejrh00@gmail.com
Fixed in r103.
Status: Fixed
Oct 31, 2011
Project Member #3 ejrh00@gmail.com
(No comment was entered for this change.)
Labels: Subproject-Compiler