diff --git a/src/newgrf_optimiser.cpp b/src/newgrf_optimiser.cpp index ae2d66d3e1..e84db215eb 100644 --- a/src/newgrf_optimiser.cpp +++ b/src/newgrf_optimiser.cpp @@ -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]; diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index 370efbaec0..3f4b714ed0 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -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) {