VarAction2: Fix tracking of whether a sprite group needs var 1C

This commit is contained in:
Jonathan G Rennison 2022-07-14 23:38:52 +01:00
parent e497f0e78d
commit ae746a1af4

View File

@ -6705,7 +6705,6 @@ static void OptimiseVarAction2Adjust(VarAction2OptimiseState &state, const GrfSp
/* Procedure call or complex adjustment */ /* Procedure call or complex adjustment */
if (adjust.operation == DSGA_OP_STO) handle_unpredictable_temp_store(); if (adjust.operation == DSGA_OP_STO) handle_unpredictable_temp_store();
if (adjust.variable == 0x7E) { if (adjust.variable == 0x7E) {
state.seen_procedure_call = true;
reset_store_values(); reset_store_values();
auto handle_group = y_combinator([&](auto handle_group, const SpriteGroup *sg) -> void { auto handle_group = y_combinator([&](auto handle_group, const SpriteGroup *sg) -> void {
if (sg == nullptr) return; if (sg == nullptr) return;
@ -6723,9 +6722,13 @@ static void OptimiseVarAction2Adjust(VarAction2OptimiseState &state, const GrfSp
} }
state.GetVarTracking(group)->in |= bits; state.GetVarTracking(group)->in |= bits;
} }
if (!state.seen_procedure_call && ((const DeterministicSpriteGroup*)sg)->dsg_flags & DSGF_REQUIRES_VAR1C) {
group->dsg_flags |= DSGF_REQUIRES_VAR1C;
}
} }
}); });
handle_group(adjust.subroutine); handle_group(adjust.subroutine);
state.seen_procedure_call = true;
} else if (adjust.operation == DSGA_OP_RST) { } else if (adjust.operation == DSGA_OP_RST) {
state.inference = VA2AIF_SINGLE_LOAD; state.inference = VA2AIF_SINGLE_LOAD;
} }
@ -7765,7 +7768,6 @@ static void OptimiseVarAction2DeterministicSpriteGroup(VarAction2OptimiseState &
std::bitset<256> pending_bits; std::bitset<256> pending_bits;
bool seen_pending = false; bool seen_pending = false;
if (!group->calculated_result) { if (!group->calculated_result) {
bool require_var1C = false;
auto handle_group = y_combinator([&](auto handle_group, const SpriteGroup *sg) -> void { auto handle_group = y_combinator([&](auto handle_group, const SpriteGroup *sg) -> void {
if (sg != nullptr && sg->type == SGT_DETERMINISTIC) { if (sg != nullptr && sg->type == SGT_DETERMINISTIC) {
VarAction2GroupVariableTracking *var_tracking = _cur.GetVarAction2GroupVariableTracking(sg, false); VarAction2GroupVariableTracking *var_tracking = _cur.GetVarAction2GroupVariableTracking(sg, false);
@ -7776,7 +7778,6 @@ static void OptimiseVarAction2DeterministicSpriteGroup(VarAction2OptimiseState &
} else { } else {
if (var_tracking != nullptr) bits |= var_tracking->in; if (var_tracking != nullptr) bits |= var_tracking->in;
} }
if (dsg->dsg_flags & DSGF_REQUIRES_VAR1C) require_var1C = true;
} }
if (sg != nullptr && sg->type == SGT_RANDOMIZED) { if (sg != nullptr && sg->type == SGT_RANDOMIZED) {
const RandomizedSpriteGroup *rsg = (const RandomizedSpriteGroup*)sg; const RandomizedSpriteGroup *rsg = (const RandomizedSpriteGroup*)sg;
@ -7831,7 +7832,6 @@ static void OptimiseVarAction2DeterministicSpriteGroup(VarAction2OptimiseState &
} }
state.GetVarTracking(group)->in |= in_bits; state.GetVarTracking(group)->in |= in_bits;
} }
if (require_var1C && !state.seen_procedure_call) group->dsg_flags |= DSGF_REQUIRES_VAR1C;
} }
bool dse_allowed = IsFeatureUsableForDSE(feature) && !HasGrfOptimiserFlag(NGOF_NO_OPT_VARACT2_DSE); bool dse_allowed = IsFeatureUsableForDSE(feature) && !HasGrfOptimiserFlag(NGOF_NO_OPT_VARACT2_DSE);
bool dse_eligible = state.enable_dse; bool dse_eligible = state.enable_dse;