Explorar el Código

* x86: Fixed bug where flags register wasn't tracked during
long-range "AddMov2LeaAdd" and "SubMov2LeaSub" optimisations

J. Gareth "Curious Kit" Moreton hace 5 meses
padre
commit
b2dd980329
Se han modificado 1 ficheros con 18 adiciones y 2 borrados
  1. 18 2
      compiler/x86/aoptx86.pas

+ 18 - 2
compiler/x86/aoptx86.pas

@@ -15738,7 +15738,15 @@ unit aoptx86;
               (
               (
                 { Instructions are guaranteed to be adjacent on -O2 and under }
                 { Instructions are guaranteed to be adjacent on -O2 and under }
                 not (cs_opt_level3 in current_settings.optimizerswitches) or
                 not (cs_opt_level3 in current_settings.optimizerswitches) or
-                not RegUsedBetween(taicpu(hp1).oper[1]^.reg, p, hp1)
+                (
+                  { If the flags are used, don't make the optimisation,
+                    otherwise they will be scrambled.  Fixes #41148 }
+                  (
+                    not RegInUsedRegs(NR_DEFAULTFLAGS, UsedRegs) or
+                    not RegUsedBetween(NR_DEFAULTFLAGS, p, hp1)
+                  ) and
+                  not RegUsedBetween(taicpu(hp1).oper[1]^.reg, p, hp1)
+                )
               ) then
               ) then
               begin
               begin
                 TransferUsedRegs(TmpUsedRegs);
                 TransferUsedRegs(TmpUsedRegs);
@@ -16003,7 +16011,15 @@ unit aoptx86;
               (
               (
                 { Instructions are guaranteed to be adjacent on -O2 and under }
                 { Instructions are guaranteed to be adjacent on -O2 and under }
                 not (cs_opt_level3 in current_settings.optimizerswitches) or
                 not (cs_opt_level3 in current_settings.optimizerswitches) or
-                not RegUsedBetween(taicpu(hp1).oper[1]^.reg, p, hp1)
+                (
+                  { If the flags are used, don't make the optimisation,
+                    otherwise they will be scrambled.  Fixes #41148 }
+                  (
+                    not RegInUsedRegs(NR_DEFAULTFLAGS, UsedRegs) or
+                    not RegUsedBetween(NR_DEFAULTFLAGS, p, hp1)
+                  ) and
+                  not RegUsedBetween(taicpu(hp1).oper[1]^.reg, p, hp1)
+                )
               ) then
               ) then
               begin
               begin
                 TransferUsedRegs(TmpUsedRegs);
                 TransferUsedRegs(TmpUsedRegs);