Browse Source

* x86: FuncMov2Func now has code to remove "mov %reg,%reg" (since it doesn't get removed in Pass 2).

J. Gareth "Curious Kit" Moreton 2 years ago
parent
commit
a7d1f7d771
1 changed files with 15 additions and 0 deletions
  1. 15 0
      compiler/x86/aoptx86.pas

+ 15 - 0
compiler/x86/aoptx86.pas

@@ -2756,6 +2756,21 @@ unit aoptx86;
                           AllocRegBetween(p_TargetReg, hp2, p, TmpUsedRegs);
                         end;
                       RemoveCurrentp(p, hp1);
+
+                      { If the Func was another MOV instruction, we might get
+                        "mov %reg,%reg" that doesn't get removed in Pass 2
+                        otherwise, so deal with it here (also do something
+                        similar with lea (%reg),%reg}
+                      if (taicpu(hp2).opcode = A_MOV) and MatchOperand(taicpu(hp2).oper[0]^, taicpu(hp2).oper[1]^.reg) then
+                        begin
+                          DebugMsg(SPeepholeOptimization + 'Mov2Nop 1a done', hp2);
+
+                          if p = hp2 then
+                            RemoveCurrentp(p)
+                          else
+                            RemoveInstruction(hp2);
+                        end;
+
                       Result := True;
                       Exit;
                     end;