View Issue Details

IDProjectCategoryView StatusLast Update
0037442FPCCompilerpublic2020-08-10 15:31
ReporterJ. Gareth Moreton Assigned ToFlorian  
PrioritylowSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Platformi386 and x86_64OSMicrosoft Windows 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037442: [Patch] Minor oversight in MovAnd2Mov 3 optimisation
DescriptionAn x86 optimisation with MOV/AND pairs does not set Result to True in order to indicate that pass 1 needs to run another iteration in order for all optimisations to be caught. This is partially disguised by the fact that pass 1 is always given an additional pass at the end, but is a little bit inconsistent, and can cause slight code differences if this additional pass is removed (experimental branch of mine), even under -O4 where no optimisations should be missed.
Steps To ReproduceApply patch and confirm correct compilation.
Additional InformationCan someone explain the necessity of the "aoc_MovAnd2Mov_3" flag? This disables the optimisation until a particular AND optimisation takes place (where Result was not set). It has an element of 'code smell' to me, because if an optimisation should not be performed until a particular set of circumstances, then I would argue that it should be moved to pass 2 instead. Setting the flag also affects ALL of the MOV/AND optimisations for the current procedure, not just the one that the AND instruction is a part of.
Tagscompiler, i386, optimizations, patch, x86, x86_64
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

J. Gareth Moreton

2020-07-29 04:06

developer  

movand2mov3oversight.patch (592 bytes)   
Index: compiler/x86/aoptx86.pas
===================================================================
--- compiler/x86/aoptx86.pas	(revision 45867)
+++ compiler/x86/aoptx86.pas	(working copy)
@@ -5863,7 +5863,10 @@
               begin
                 taicpu(p).loadreg(0, taicpu(p).oper[1]^.reg);
                 if taicpu(p).opsize = S_L then
-                  Include(OptsToCheck,aoc_MovAnd2Mov_3);
+                  begin
+                    Include(OptsToCheck,aoc_MovAnd2Mov_3);
+                    Result := True;
+                  end;
               end;
           end;
 
movand2mov3oversight.patch (592 bytes)   

Florian

2020-08-10 15:31

administrator   ~0124729

The idea is to avoid expensive look aheads from mov instructions. Only if an and $fff... is encountered, another pass1 is carried out and for this particular optmizations is searched.

Florian

2020-08-10 15:31

administrator   ~0124730

Patch is applied meanwhile.

Issue History

Date Modified Username Field Change
2020-07-29 04:06 J. Gareth Moreton New Issue
2020-07-29 04:06 J. Gareth Moreton File Added: movand2mov3oversight.patch
2020-07-29 04:06 J. Gareth Moreton Priority normal => low
2020-07-29 04:06 J. Gareth Moreton FPCTarget => -
2020-07-29 04:06 J. Gareth Moreton Tag Attached: patch
2020-07-29 04:06 J. Gareth Moreton Tag Attached: compiler
2020-07-29 04:06 J. Gareth Moreton Tag Attached: optimizations
2020-07-29 04:06 J. Gareth Moreton Tag Attached: x86_64
2020-07-29 04:06 J. Gareth Moreton Tag Attached: x86
2020-07-29 04:06 J. Gareth Moreton Tag Attached: i386
2020-07-29 04:07 J. Gareth Moreton Additional Information Updated View Revisions
2020-08-10 15:31 Florian Note Added: 0124729
2020-08-10 15:31 Florian Assigned To => Florian
2020-08-10 15:31 Florian Status new => resolved
2020-08-10 15:31 Florian Resolution open => fixed
2020-08-10 15:31 Florian Fixed in Version => 3.3.1
2020-08-10 15:31 Florian Note Added: 0124730