identify add for the purpose of optimising conditions

This commit is contained in:
Fabian 2022-11-04 18:36:30 -06:00
parent 92313f582c
commit 60b555107f
3 changed files with 28 additions and 5 deletions

View file

@ -340,7 +340,12 @@ fn gen_get_flags_changed(builder: &mut WasmBuilder) {
}
fn gen_get_last_result(builder: &mut WasmBuilder, previous_instruction: &Instruction) {
match previous_instruction {
Instruction::Sub {
Instruction::Add {
dest: InstructionOperandDest::WasmLocal(l),
opsize: OPSIZE_32,
..
}
| Instruction::Sub {
dest: InstructionOperandDest::WasmLocal(l),
opsize: OPSIZE_32,
..
@ -1630,7 +1635,7 @@ pub fn gen_getzf(ctx: &mut JitContext, negate: ConditionNegate) {
}
}
},
Instruction::Cmp { .. } | Instruction::Sub { .. } => {
Instruction::Cmp { .. } | Instruction::Sub { .. } | Instruction::Add { .. } => {
gen_profiler_stat_increment(ctx.builder, profiler::stat::CONDITION_OPTIMISED);
gen_get_last_result(ctx.builder, &ctx.previous_instruction);
if negate == ConditionNegate::False {
@ -1757,6 +1762,7 @@ pub fn gen_getsf(ctx: &mut JitContext, negate: ConditionNegate) {
match &ctx.previous_instruction {
Instruction::Cmp { opsize, .. }
| Instruction::Sub { opsize, .. }
| Instruction::Add { opsize, .. }
| Instruction::Arithmetic { opsize, .. } => {
let &opsize = opsize;
gen_profiler_stat_increment(ctx.builder, profiler::stat::CONDITION_OPTIMISED);
@ -1834,7 +1840,7 @@ pub fn gen_getof(ctx: &mut JitContext) {
});
ctx.builder.and_i32();
},
&Instruction::Other | Instruction::Arithmetic { .. } => {
Instruction::Add { .. } | Instruction::Arithmetic { .. } | Instruction::Other => {
// TODO: add
gen_profiler_stat_increment(ctx.builder, profiler::stat::CONDITION_UNOPTIMISED);
gen_get_flags_changed(ctx.builder);

View file

@ -271,6 +271,11 @@ pub enum Instruction {
source: InstructionOperand,
opsize: i32,
},
Add {
dest: InstructionOperandDest,
source: InstructionOperand,
opsize: i32,
},
// Any instruction that sets last_result
Arithmetic {
dest: InstructionOperandDest,

View file

@ -954,9 +954,15 @@ macro_rules! define_instruction_read_write_mem32(
);
fn gen_add8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {
ctx.current_instruction = Instruction::Arithmetic {
ctx.current_instruction = Instruction::Add {
opsize: OPSIZE_8,
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)
},
};
ctx.builder.const_i32(global_pointers::last_op1 as i32);
@ -979,9 +985,15 @@ fn gen_add8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &Loc
.load_fixed_u8(global_pointers::last_result as u32);
}
fn gen_add32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {
ctx.current_instruction = Instruction::Arithmetic {
ctx.current_instruction = Instruction::Add {
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);