From 949081837bf06c0971e241a36d3e615809edfbf3 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 4 Nov 2022 15:28:17 -0600 Subject: [PATCH] optimise sub; jbe --- src/rust/codegen.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/rust/codegen.rs b/src/rust/codegen.rs index 6d2548cc..c357a8f0 100644 --- a/src/rust/codegen.rs +++ b/src/rust/codegen.rs @@ -1939,19 +1939,24 @@ pub fn gen_test_be(ctx: &mut JitContext, negate: ConditionNegate) { Instruction::Sub { opsize, dest: _, - source: _, + source, } => { gen_profiler_stat_increment(ctx.builder, profiler::stat::CONDITION_OPTIMISED); gen_get_last_op1(ctx.builder, &ctx.previous_instruction); - // Note: Can only use register if it's different from dest (being lazy here and just using op1 and result) - gen_get_last_op1(ctx.builder, &ctx.previous_instruction); - gen_get_last_result(ctx.builder, &ctx.previous_instruction); - ctx.builder.sub_i32(); - if *opsize == OPSIZE_8 || *opsize == OPSIZE_16 { - ctx.builder - .const_i32(if *opsize == OPSIZE_8 { 0xFF } else { 0xFFFF }); - ctx.builder.and_i32(); + match (opsize, source) { + (&OPSIZE_32, InstructionOperand::WasmLocal(l)) => ctx.builder.get_local(l), + (_, &InstructionOperand::Immediate(i)) => ctx.builder.const_i32(i), + _ => { + gen_get_last_op1(ctx.builder, &ctx.previous_instruction); + gen_get_last_result(ctx.builder, &ctx.previous_instruction); + ctx.builder.sub_i32(); + if *opsize == OPSIZE_8 || *opsize == OPSIZE_16 { + ctx.builder + .const_i32(if *opsize == OPSIZE_8 { 0xFF } else { 0xFFFF }); + ctx.builder.and_i32(); + } + }, } if negate == ConditionNegate::True {