Browse Source

* x86: Correct fileinfo and some refactoring for imul2leashl optimisation

J. Gareth "Curious Kit" Moreton 3 years ago
parent
commit
f19b390c68
1 changed files with 12 additions and 6 deletions
  1. 12 6
      compiler/x86/aoptx86.pas

+ 12 - 6
compiler/x86/aoptx86.pas

@@ -1562,7 +1562,7 @@ unit aoptx86;
     function TX86AsmOptimizer.PrePeepholeOptIMUL(var p : tai) : boolean;
     function TX86AsmOptimizer.PrePeepholeOptIMUL(var p : tai) : boolean;
       var
       var
         opsize : topsize;
         opsize : topsize;
-        hp1 : tai;
+        hp1, hp2 : tai;
         tmpref : treference;
         tmpref : treference;
         ShiftValue : Cardinal;
         ShiftValue : Cardinal;
         BaseValue : TCGInt;
         BaseValue : TCGInt;
@@ -1584,10 +1584,11 @@ unit aoptx86;
              { change "imul $1, reg1, reg2" to "mov reg1, reg2" }
              { change "imul $1, reg1, reg2" to "mov reg1, reg2" }
               begin
               begin
                 hp1 := taicpu.Op_Reg_Reg(A_MOV, opsize, taicpu(p).oper[1]^.reg,taicpu(p).oper[2]^.reg);
                 hp1 := taicpu.Op_Reg_Reg(A_MOV, opsize, taicpu(p).oper[1]^.reg,taicpu(p).oper[2]^.reg);
-                InsertLLItem(p.previous, p.next, hp1);
+                taicpu(hp1).fileinfo := taicpu(p).fileinfo;
+                asml.InsertAfter(hp1, p);
                 DebugMsg(SPeepholeOptimization + 'Imul2Mov done',p);
                 DebugMsg(SPeepholeOptimization + 'Imul2Mov done',p);
-                p.free;
-                p := hp1;
+                RemoveCurrentP(p, hp1);
+                Result := True;
               end
               end
           else if ((taicpu(p).ops <= 2) or
           else if ((taicpu(p).ops <= 2) or
               (taicpu(p).oper[2]^.typ = Top_Reg)) and
               (taicpu(p).oper[2]^.typ = Top_Reg)) and
@@ -1630,8 +1631,13 @@ unit aoptx86;
                   taicpu(hp1).fileinfo:=taicpu(p).fileinfo;
                   taicpu(hp1).fileinfo:=taicpu(p).fileinfo;
                   RemoveCurrentP(p, hp1);
                   RemoveCurrentP(p, hp1);
                   if ShiftValue>0 then
                   if ShiftValue>0 then
-                    AsmL.InsertAfter(taicpu.op_const_reg(A_SHL, opsize, ShiftValue, taicpu(hp1).oper[1]^.reg),hp1);
-              end;
+                    begin
+                      hp2 := taicpu.op_const_reg(A_SHL, opsize, ShiftValue, taicpu(hp1).oper[1]^.reg);
+                      AsmL.InsertAfter(hp2,hp1);
+                      taicpu(hp2).fileinfo:=taicpu(hp1).fileinfo;
+                    end;
+                  Result := True;
+                end;
             end;
             end;
       end;
       end;