VarAction2: Remove mul and div operations with constant 1

pull/441/head
Jonathan G Rennison 2 years ago
parent 669b3f2e04
commit 419c356f30

@ -1097,6 +1097,10 @@ void OptimiseVarAction2Adjust(VarAction2OptimiseState &state, const GrfSpecFeatu
} else if (adjust.and_mask == 0 && IsEvalAdjustWithZeroAlwaysZero(adjust.operation)) {
/* Operation always returns 0, replace it and any useless prior operations */
replace_with_constant_load(0);
} else if (adjust.variable == 0x1A && adjust.shift_num == 0 && adjust.and_mask == 1 && IsEvalAdjustWithOneRemovable(adjust.operation)) {
/* Delete useless operations with a constant of 1 */
group->adjusts.pop_back();
state.inference = prev_inference;
} else {
if (adjust.variable == 0x7D && adjust.shift_num == 0 && adjust.and_mask == get_full_mask() && IsEvalAdjustOperationCommutative(adjust.operation) && group->adjusts.size() >= 2) {
DeterministicSpriteGroupAdjust &prev = group->adjusts[group->adjusts.size() - 2];

@ -225,6 +225,19 @@ inline bool IsEvalAdjustWithZeroAlwaysZero(DeterministicSpriteGroupAdjustOperati
}
}
inline bool IsEvalAdjustWithOneRemovable(DeterministicSpriteGroupAdjustOperation op)
{
switch (op) {
case DSGA_OP_MUL:
case DSGA_OP_SDIV:
case DSGA_OP_UDIV:
return true;
default:
return false;
}
}
inline bool IsEvalAdjustWithSideEffects(DeterministicSpriteGroupAdjustOperation op)
{
switch (op) {

Loading…
Cancel
Save