[fpc-devel] Looking for some general clarification on how exactly revision #43175 "fixes" bugtracker issue #0036139

Jonas Maebe jonas at freepascal.org
Sun Oct 13 09:42:35 CEST 2019


On 2019-10-13 01:54, Ben Grasset wrote:

> I guess this doesn't matter too much in the grand scheme of things, but 
> I'm somewhat confused by it, so I thought I'd ask.
> 
> Specifically, the reporter of that issue, calling themselves 
> "Alexander", used the following program as an "example" of what they 
> called "too aggressive optimization":
> 
> program test:
> var v:longword;
> begin
> if v=2 then while true do ;
> end.
> 
> To me, that just shows a while loop that will very obviously be exited 
> immediately in all cases, because "v" is very obviously *not* equal to 
> 2. Yet they used a (tiny) snippet of assembler from this and deemed it 
> "incorrect", without making any attempt to clarify what they meant.

The snippet came from the compiled program. It showed that the "while 
true do ;" infinite loop got removed by the peephole optimiser (as also 
mentioned by Martin). That was wrong. The peephole optimiser does not 
perform any dead code analyses. It's only supposed to transform code 
patterns into equivalent (but hopefully faster) ones.

Adding a "v:=2;" statement at the start of the program, which would make 
the loop reachable, did not affect the generated code (i.e., the loop 
was still removed).


Jonas


More information about the fpc-devel mailing list