[fpc-devel] Internal jump instructions for longer conditional jumps

Martin Frb lazarus at mfriebe.de
Tue Apr 21 00:28:04 CEST 2020


On 21/04/2020 00:05, J. Gareth Moreton wrote:
> Hi Martin,
>
> Can you remind me which version of FPC you're compiling with, and the 
> compiler options specified? My jump optimisation code in the trunk 
> should eliminate most of those jump pads and 'conditional jump 
> inversions'.

Fpc 3.0.4
-gh -g -gw -godwarfsets  -gl   -dCR   -Ct -Co -Cr -Ci  -gt  -Sa  -ve -vw 
-vn  -vi       -O-  -CX  -WC

My concern right here was not about the performance.

This is about the line info applied to those.
In this case a "jmp" that I guess belongs after the "then begin end" is 
attributed to the last line in the "then begin end".
Simply because no line exists between the last line of "then" and the 
first line of "else". So the "then" line extends until the next line 
starts, and eats anything that is inbetwen.

In the example below, a single step from the marked line, should go to 
DoGood().
But it does go to "bar" (which is not executed, but contains the jmp)

That is obviously irritating.
GDB somehow detects that.
Now, I added this to fpdebug too. Though currently with a limit, as to 
how many such jumps are stepped over. That limit may have to go.

The debugger has to deal with this.
    IF true then begin
       IF false then begin  // Single step from here
           foo;
           bar;
       end;
    end
    else begin
      ...
   end;
   DoGood();

----------
While the debugger runs best with -O-, if you do optimizations mind that 
line info may need adjustments.
You may well be aware of it, but it also is an easy to make oversight. 
So if you are interested below a real case:

Long ago there was an issue (fixed by now)
line 1:  mov  const => mem
line 2:  mov mem => reg
line 2: ....

2nd line was correctly removed.
But somehow it ended up
line 1: move const => reg
line 2:  mov reg => mem
line 2: ....

Which meant that when you stepped over line 1, the memory (which the 
debugger shows for the variable) was not yet updated. The debugger 
showed the outdated value.
https://bugs.freepascal.org/view.php?id=25584




More information about the fpc-devel mailing list