Browse Source

* RiscV: extend Addi0Op2Op

florian 10 months ago
parent
commit
e9fa0510d0
1 changed files with 9 additions and 3 deletions
  1. 9 3
      compiler/riscv/aoptcpurv.pas

+ 9 - 3
compiler/riscv/aoptcpurv.pas

@@ -56,7 +56,8 @@ type
 implementation
 implementation
 
 
   uses
   uses
-    cutils;
+    cutils,
+    verbose;
 
 
   function MatchInstruction(const instr: tai; const op: TCommonAsmOps; const AConditions: TAsmConds = []): boolean;
   function MatchInstruction(const instr: tai; const op: TCommonAsmOps; const AConditions: TAsmConds = []): boolean;
     begin
     begin
@@ -333,11 +334,16 @@ implementation
          GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
          GetNextInstructionUsingReg(p, hp1, taicpu(p).oper[0]^.reg) and
          MatchInstruction(hp1, [A_SUB{$ifdef riscv64}{$endif}]) and
          MatchInstruction(hp1, [A_SUB{$ifdef riscv64}{$endif}]) and
          (taicpu(hp1).ops=3) and
          (taicpu(hp1).ops=3) and
-         MatchOperand(taicpu(p).oper[0]^,taicpu(hp1).oper[2]^) and
+         (MatchOperand(taicpu(p).oper[0]^,taicpu(hp1).oper[2]^) or MatchOperand(taicpu(p).oper[0]^,taicpu(hp1).oper[1]^)) and
          (not RegModifiedBetween(taicpu(p).oper[1]^.reg, p,hp1)) and
          (not RegModifiedBetween(taicpu(p).oper[1]^.reg, p,hp1)) and
          RegEndOfLife(taicpu(p).oper[0]^.reg, taicpu(hp1)) then
          RegEndOfLife(taicpu(p).oper[0]^.reg, taicpu(hp1)) then
         begin
         begin
-          taicpu(hp1).loadreg(2,taicpu(p).oper[1]^.reg);
+          if MatchOperand(taicpu(p).oper[0]^,taicpu(hp1).oper[2]^) then
+            taicpu(hp1).loadreg(2,taicpu(p).oper[1]^.reg)
+          else if MatchOperand(taicpu(p).oper[0]^,taicpu(hp1).oper[1]^) then
+            taicpu(hp1).loadreg(1,taicpu(p).oper[1]^.reg)
+          else
+            Internalerror(2024093001);
 
 
           DebugMsg('Peephole Addi0Op2Op performed', hp1);
           DebugMsg('Peephole Addi0Op2Op performed', hp1);