certain jump optimizations leave referenced labels without matching jump
Original Reporter info from Mantis: MaKa
-
Reporter name: M.K.
Original Reporter info from Mantis: MaKa
- Reporter name: M.K.
Description:
Some jump/cf optimizations leave referenced labels after optimizing the according jumps out.
Further optimizations may be less effective due to blocking labels and new optimizations may cause problems due to false assumptions.
Steps to reproduce:
Reproduction depends on architecture and optimization settings.
Known example for x86_64 Linux @ rev 17060:
-
$fpc -atnlr compiler/cutils.pas
1.a. or use attached source compiles -
$egrep -o ".Lj[0-9]+" compiler/cutils.s | sort | uniq -c | egrep " 1 .L"
example output:
1 .Lj1010
1 .Lj119
1 .Lj1224
1 .Lj1231
1 .Lj128
1 .Lj1297
1 .Lj1302
1 .Lj1306
1 .Lj1309
1 .Lj1363
1 .Lj1379
1 .Lj1459
1 .Lj1466
1 .Lj1484
1 .Lj1485
1 .Lj334
1 .Lj345
1 .Lj444
1 .Lj45
1 .Lj471
1 .Lj488
1 .Lj495
1 .Lj562
1 .Lj569
1 .Lj625
1 .Lj757
open editor and cross check
since compiler/aopt* is used in multiple targets, the problem is assumed to be consistent for those targets
Additional information:
Added a first patch-draft for aoptobj.pas/aoptbase.pas
* use labelCanBeSkipped from aoptbase.pas for FindAnyLabel function which should find existing code labels after a jump (didn't take unused labels into account)
* added 2 derefs where jumps are removed without derefing the label
* added sources for current
Problem 1.: only tested with compiler_cycle, compiles fine/no crashes
Problem 2.: there are still remaining Labels with wrong refcount, which may result from other optimizations.
Problem 3.: i386 optimization base reused this code -> same problem but mixed with several other optimizations
--
Currently there is no visible side effect because the label refcount is positive and there are less to non optimizations which operate on control flow. So major intention for this report is to provide information for those hitting the problem or (re)working on CF/Jump optimizations.
Mantis conversion info:
- Mantis ID: 18858
- Fixed in version: 2.6.0
- Fixed in revision: 17067 (#4be36c4b)