From 3aa0ccb97b6b40f601be6dd1f8689189ed774147 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 6 Jun 2022 22:17:14 +0100 Subject: [PATCH] VarAction2: Optimise OR which always produces 1 --- src/newgrf.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 056131b9c5..8d7cbe37ed 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -6058,6 +6058,10 @@ static void OptimiseVarAction2Adjust(VarAction2OptimiseState &state, const GrfSp state.inference |= non_const_var_inference; break; case DSGA_OP_OR: + if (adjust.variable == 0x1A && adjust.shift_num == 0 && adjust.and_mask == 1 && (prev_inference & VA2AIF_ONE_OR_ZERO)) { + replace_with_constant_load(1); + break; + } if (adjust.and_mask <= 1) state.inference = prev_inference & (VA2AIF_SIGNED_NON_NEGATIVE | VA2AIF_ONE_OR_ZERO); state.inference |= prev_inference & (VA2AIF_SIGNED_NON_NEGATIVE | VA2AIF_ONE_OR_ZERO) & non_const_var_inference; break;