From bb0f37bbce73deb88530fe9a9dbe37f8465a2059 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 4 Nov 2022 14:48:59 -0600 Subject: [PATCH] optimise sub; jc --- src/rust/codegen.rs | 11 ++++++++--- src/rust/jit.rs | 1 + src/rust/jit_instructions.rs | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/rust/codegen.rs b/src/rust/codegen.rs index d4afc43f..6d2548cc 100644 --- a/src/rust/codegen.rs +++ b/src/rust/codegen.rs @@ -343,6 +343,7 @@ fn gen_get_last_result(builder: &mut WasmBuilder, previous_instruction: &Instruc Instruction::Sub { dest: InstructionOperandDest::WasmLocal(l), opsize: OPSIZE_32, + .. } | Instruction::Arithmetic { dest: InstructionOperandDest::WasmLocal(l), @@ -1692,8 +1693,8 @@ pub fn gen_getzf(ctx: &mut JitContext, negate: ConditionNegate) { pub fn gen_getcf(ctx: &mut JitContext, negate: ConditionNegate) { match &ctx.previous_instruction { - Instruction::Cmp { source, opsize, .. } => { - // TODO: add/sub + Instruction::Cmp { source, opsize, .. } | Instruction::Sub { source, opsize, .. } => { + // TODO: add // Note: x < y and x < x - y can be used interchangeably (see getcf) gen_profiler_stat_increment(ctx.builder, profiler::stat::CONDITION_OPTIMISED); gen_get_last_op1(ctx.builder, &ctx.previous_instruction); @@ -1935,7 +1936,11 @@ pub fn gen_test_be(ctx: &mut JitContext, negate: ConditionNegate) { ctx.builder.leu_i32(); } }, - Instruction::Sub { opsize, dest: _ } => { + Instruction::Sub { + opsize, + dest: _, + source: _, + } => { gen_profiler_stat_increment(ctx.builder, profiler::stat::CONDITION_OPTIMISED); gen_get_last_op1(ctx.builder, &ctx.previous_instruction); diff --git a/src/rust/jit.rs b/src/rust/jit.rs index 18eec8f5..a7ec551b 100644 --- a/src/rust/jit.rs +++ b/src/rust/jit.rs @@ -268,6 +268,7 @@ pub enum Instruction { }, Sub { dest: InstructionOperandDest, + source: InstructionOperand, opsize: i32, }, // Any instruction that sets last_result diff --git a/src/rust/jit_instructions.rs b/src/rust/jit_instructions.rs index 4e1d8ceb..988aa88c 100644 --- a/src/rust/jit_instructions.rs +++ b/src/rust/jit_instructions.rs @@ -1025,6 +1025,12 @@ fn gen_sub32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &Lo ctx.current_instruction = Instruction::Sub { opsize: OPSIZE_32, dest: local_to_instruction_operand(ctx, dest_operand), + source: if source_operand.eq_local(dest_operand) { + InstructionOperand::Other // aliasing + } + else { + source_operand.to_instruction_operand(ctx) + }, }; codegen::gen_set_last_op1(ctx.builder, &dest_operand);