VarAction2: Remove operations which always do nothing when applied to 0
This commit is contained in:
@@ -5862,6 +5862,10 @@ static void OptimiseVarAction2Adjust(VarAction2OptimiseState &state, const GrfSp
|
|||||||
} else if ((prev_inference & VA2AIF_HAVE_CONSTANT) && adjust.variable == 0x1A && IsEvalAdjustUsableForConstantPropagation(adjust.operation)) {
|
} else if ((prev_inference & VA2AIF_HAVE_CONSTANT) && adjust.variable == 0x1A && IsEvalAdjustUsableForConstantPropagation(adjust.operation)) {
|
||||||
/* Reduce constant operation on previous constant */
|
/* Reduce constant operation on previous constant */
|
||||||
replace_with_constant_load(EvaluateDeterministicSpriteGroupAdjust(group->size, adjust, nullptr, state.current_constant, UINT_MAX));
|
replace_with_constant_load(EvaluateDeterministicSpriteGroupAdjust(group->size, adjust, nullptr, state.current_constant, UINT_MAX));
|
||||||
|
} else if ((prev_inference & VA2AIF_HAVE_CONSTANT) && state.current_constant == 0 && adjust.variable != 0x7E && IsEvalAdjustWithZeroLastValueAlwaysZero(adjust.operation)) {
|
||||||
|
/* Remove operation which does nothing when applied to 0 */
|
||||||
|
group->adjusts.pop_back();
|
||||||
|
state.inference = prev_inference;
|
||||||
} else if ((prev_inference & VA2AIF_HAVE_CONSTANT) && IsEvalAdjustOperationOnConstantEffectiveLoad(adjust.operation, state.current_constant)) {
|
} else if ((prev_inference & VA2AIF_HAVE_CONSTANT) && IsEvalAdjustOperationOnConstantEffectiveLoad(adjust.operation, state.current_constant)) {
|
||||||
/* Convert operation to a load */
|
/* Convert operation to a load */
|
||||||
DeterministicSpriteGroupAdjust current = group->adjusts.back();
|
DeterministicSpriteGroupAdjust current = group->adjusts.back();
|
||||||
|
@@ -307,6 +307,27 @@ inline bool IsEvalAdjustOperationOnConstantEffectiveLoad(DeterministicSpriteGrou
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool IsEvalAdjustWithZeroLastValueAlwaysZero(DeterministicSpriteGroupAdjustOperation op)
|
||||||
|
{
|
||||||
|
switch (op) {
|
||||||
|
case DSGA_OP_SDIV:
|
||||||
|
case DSGA_OP_SMOD:
|
||||||
|
case DSGA_OP_UDIV:
|
||||||
|
case DSGA_OP_UMOD:
|
||||||
|
case DSGA_OP_UMIN:
|
||||||
|
case DSGA_OP_MUL:
|
||||||
|
case DSGA_OP_AND:
|
||||||
|
case DSGA_OP_ROR:
|
||||||
|
case DSGA_OP_SHL:
|
||||||
|
case DSGA_OP_SHR:
|
||||||
|
case DSGA_OP_SAR:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct DeterministicSpriteGroupAdjust {
|
struct DeterministicSpriteGroupAdjust {
|
||||||
DeterministicSpriteGroupAdjustOperation operation;
|
DeterministicSpriteGroupAdjustOperation operation;
|
||||||
DeterministicSpriteGroupAdjustType type;
|
DeterministicSpriteGroupAdjustType type;
|
||||||
|
Reference in New Issue
Block a user