patch up some savestate issues
[pcsx_rearmed.git] / deps / lightrec / optimizer.c
index 38d77d8..c01e024 100644 (file)
@@ -867,6 +867,12 @@ static void lightrec_reset_syncs(struct block *block)
        }
 }
 
+static void maybe_remove_load_delay(struct opcode *op)
+{
+       if (op_flag_load_delay(op->flags) && opcode_is_load(op->c))
+               op->flags &= ~LIGHTREC_LOAD_DELAY;
+}
+
 static int lightrec_transform_ops(struct lightrec_state *state, struct block *block)
 {
        struct opcode *op, *list = block->opcode_list;
@@ -907,6 +913,9 @@ static int lightrec_transform_ops(struct lightrec_state *state, struct block *bl
                                   (v[op->i.rs].value ^ v[op->i.rt].value)) {
                                pr_debug("Found never-taken BEQ\n");
 
+                               if (!op_flag_no_ds(op->flags))
+                                       maybe_remove_load_delay(&list[i + 1]);
+
                                local = op_flag_local_branch(op->flags);
                                op->opcode = 0;
                                op->flags = 0;
@@ -931,6 +940,9 @@ static int lightrec_transform_ops(struct lightrec_state *state, struct block *bl
                                   v[op->i.rs].value == v[op->i.rt].value) {
                                pr_debug("Found never-taken BNE\n");
 
+                               if (!op_flag_no_ds(op->flags))
+                                       maybe_remove_load_delay(&list[i + 1]);
+
                                local = op_flag_local_branch(op->flags);
                                op->opcode = 0;
                                op->flags = 0;
@@ -959,6 +971,9 @@ static int lightrec_transform_ops(struct lightrec_state *state, struct block *bl
                            v[op->i.rs].value & BIT(31)) {
                                pr_debug("Found never-taken BGTZ\n");
 
+                               if (!op_flag_no_ds(op->flags))
+                                       maybe_remove_load_delay(&list[i + 1]);
+
                                local = op_flag_local_branch(op->flags);
                                op->opcode = 0;
                                op->flags = 0;
@@ -1017,6 +1032,9 @@ static int lightrec_transform_ops(struct lightrec_state *state, struct block *bl
                                } else {
                                        pr_debug("Found never-taken BLTZ/BGEZ\n");
 
+                                       if (!op_flag_no_ds(op->flags))
+                                               maybe_remove_load_delay(&list[i + 1]);
+
                                        local = op_flag_local_branch(op->flags);
                                        op->opcode = 0;
                                        op->flags = 0;