drc: detect unoptimized stack reloads
authornotaz <notasas@gmail.com>
Wed, 22 Jan 2025 01:11:12 +0000 (03:11 +0200)
committernotaz <notasas@gmail.com>
Fri, 24 Jan 2025 23:34:41 +0000 (01:34 +0200)
libpcsxcore/new_dynarec/new_dynarec.c

index 9b090e4..86333a8 100644 (file)
@@ -7434,6 +7434,17 @@ static noinline void pass2a_unneeded_other(void)
           break;
       }
     }
+    // rm redundant stack loads (unoptimized code, assuming no io mem access through sp)
+    if (i > 0 && dops[i].is_load && dops[i].rs1 == 29 && dops[i].ls_type == LS_32
+        && dops[i-1].is_store && dops[i-1].rs1 == 29 && dops[i-1].ls_type == LS_32
+        && dops[i-1].rs2 == dops[i].rt1 && !dops[i-1].is_ds && i < slen - 1
+        && dops[i+1].rs1 != dops[i].rt1 && dops[i+1].rs2 != dops[i].rt1
+        && !dops[i].bt && cinfo[i].imm == cinfo[i-1].imm)
+    {
+      cinfo[i].imm = 0;
+      memset(&dops[i], 0, sizeof(dops[i]));
+      dops[i].itype = NOP;
+    }
   }
 }