VarAction2: Detect and replace operations which always produce 0
This commit is contained in:
@@ -5677,6 +5677,27 @@ static void NewSpriteGroup(ByteReader *buf)
|
|||||||
/* Delete useless zero operations */
|
/* Delete useless zero operations */
|
||||||
group->adjusts.pop_back();
|
group->adjusts.pop_back();
|
||||||
inference = prev_inference;
|
inference = prev_inference;
|
||||||
|
} else if (adjust.and_mask == 0 && IsEvalAdjustWithZeroAlwaysZero(adjust.operation)) {
|
||||||
|
/* Operation always returns 0, replace it and any useless prior operations */
|
||||||
|
group->adjusts.pop_back();
|
||||||
|
while (!group->adjusts.empty()) {
|
||||||
|
const DeterministicSpriteGroupAdjust &prev = group->adjusts.back();
|
||||||
|
if (prev.variable != 0x7E && !IsEvalAdjustWithSideEffects(prev.operation)) {
|
||||||
|
/* Delete useless operation */
|
||||||
|
group->adjusts.pop_back();
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DeterministicSpriteGroupAdjust &replacement = group->adjusts.emplace_back();
|
||||||
|
replacement.operation = group->adjusts.size() == 1 ? DSGA_OP_ADD : DSGA_OP_RST;
|
||||||
|
replacement.variable = 0x1A;
|
||||||
|
replacement.shift_num = 0;
|
||||||
|
replacement.type = DSGA_TYPE_NONE;
|
||||||
|
replacement.and_mask = 0;
|
||||||
|
replacement.add_val = 0;
|
||||||
|
replacement.divmod_val = 0;
|
||||||
|
inference = VA2AIF_SIGNED_NON_NEGATIVE | VA2AIF_ONE_OR_ZERO | VA2AIF_PREV_MASK_ADJUST;
|
||||||
} else {
|
} else {
|
||||||
switch (adjust.operation) {
|
switch (adjust.operation) {
|
||||||
case DSGA_OP_SMIN:
|
case DSGA_OP_SMIN:
|
||||||
|
@@ -186,6 +186,32 @@ inline bool IsEvalAdjustWithZeroRemovable(DeterministicSpriteGroupAdjustOperatio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool IsEvalAdjustWithZeroAlwaysZero(DeterministicSpriteGroupAdjustOperation op)
|
||||||
|
{
|
||||||
|
switch (op) {
|
||||||
|
case DSGA_OP_UMIN:
|
||||||
|
case DSGA_OP_MUL:
|
||||||
|
case DSGA_OP_AND:
|
||||||
|
case DSGA_OP_RST:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool IsEvalAdjustWithSideEffects(DeterministicSpriteGroupAdjustOperation op)
|
||||||
|
{
|
||||||
|
switch (op) {
|
||||||
|
case DSGA_OP_STO:
|
||||||
|
case DSGA_OP_STOP:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline bool IsEvalAdjustUsableForConstantPropagation(DeterministicSpriteGroupAdjustOperation op)
|
inline bool IsEvalAdjustUsableForConstantPropagation(DeterministicSpriteGroupAdjustOperation op)
|
||||||
{
|
{
|
||||||
switch (op) {
|
switch (op) {
|
||||||
|
Reference in New Issue
Block a user