From 63f21925b3e68d8883dbe4275c2c4dc8865cfbab Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 20 Sep 2022 00:26:56 +0300 Subject: [PATCH] Avoid useless move --- ir_aarch64.dasc | 23 ++++++++++++++--------- ir_x86.dasc | 23 ++++++++++++++--------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/ir_aarch64.dasc b/ir_aarch64.dasc index 87aad82..756cc37 100644 --- a/ir_aarch64.dasc +++ b/ir_aarch64.dasc @@ -4319,8 +4319,13 @@ static int ir_emit_dessa_move(ir_ctx *ctx, uint8_t type, ir_ref from, ir_ref to) ir_emit_load(ctx, type, from_reg, from); } if (to_reg != IR_REG_NONE && (to_reg & IR_REG_SPILL_STORE)) { - to_reg &= ~IR_REG_SPILL_STORE; - spill_store = 1; + if (from_reg != IR_REG_NONE) { + /* store directly into spill slot (valid only when to_reg register is not reused) */ + to_reg = IR_REG_NONE; + } else { + to_reg &= ~IR_REG_SPILL_STORE; + spill_store = 1; + } } if (from_reg != IR_REG_NONE && to_reg != IR_REG_NONE) { if (from_reg != to_reg) { @@ -4347,13 +4352,13 @@ static int ir_emit_dessa_move(ir_ctx *ctx, uint8_t type, ir_ref from, ir_ref to) ir_emit_load(ctx, type, from_reg, from); } if (to_reg != IR_REG_NONE && (to_reg & IR_REG_SPILL_STORE)) { -#if 1 - /* store directly into spill slot (valid only when to_reg register is not reused) */ - to_reg = IR_REG_NONE; -#else - to_reg &= ~IR_REG_SPILL_STORE; - spill_store = 1; -#endif + if (from_reg != IR_REG_NONE) { + /* store directly into spill slot (valid only when to_reg register is not reused) */ + to_reg = IR_REG_NONE; + } else { + to_reg &= ~IR_REG_SPILL_STORE; + spill_store = 1; + } } if (from_reg != IR_REG_NONE && to_reg != IR_REG_NONE) { if (from_reg != to_reg) { diff --git a/ir_x86.dasc b/ir_x86.dasc index 7daf06c..4387dc6 100644 --- a/ir_x86.dasc +++ b/ir_x86.dasc @@ -6736,8 +6736,13 @@ static int ir_emit_dessa_move(ir_ctx *ctx, uint8_t type, ir_ref from, ir_ref to) ir_emit_load(ctx, type, from_reg, from); } if (to_reg != IR_REG_NONE && (to_reg & IR_REG_SPILL_STORE)) { - to_reg &= ~IR_REG_SPILL_STORE; - spill_store = 1; + if (from_reg != IR_REG_NONE) { + /* store directly into spill slot (valid only when to_reg register is not reused) */ + to_reg = IR_REG_NONE; + } else { + to_reg &= ~IR_REG_SPILL_STORE; + spill_store = 1; + } } if (from_reg != IR_REG_NONE && to_reg != IR_REG_NONE) { if (from_reg != to_reg) { @@ -6769,13 +6774,13 @@ static int ir_emit_dessa_move(ir_ctx *ctx, uint8_t type, ir_ref from, ir_ref to) ir_emit_load(ctx, type, from_reg, from); } if (to_reg != IR_REG_NONE && (to_reg & IR_REG_SPILL_STORE)) { -#if 1 - /* store directly into spill slot (valid only when to_reg register is not reused) */ - to_reg = IR_REG_NONE; -#else - to_reg &= ~IR_REG_SPILL_STORE; - spill_store = 1; -#endif + if (from_reg != IR_REG_NONE) { + /* store directly into spill slot (valid only when to_reg register is not reused) */ + to_reg = IR_REG_NONE; + } else { + to_reg &= ~IR_REG_SPILL_STORE; + spill_store = 1; + } } if (from_reg != IR_REG_NONE && to_reg != IR_REG_NONE) { if (from_reg != to_reg) {