From 3983e78a436a6ac7f8f87b989eebda12de1a5ca3 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 24 Apr 2024 23:03:43 +0300 Subject: [PATCH] Use SWAP_REFS() macro --- ir_aarch64.dasc | 4 +--- ir_fold.h | 16 ++++------------ ir_x86.dasc | 9 ++------- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/ir_aarch64.dasc b/ir_aarch64.dasc index 4184d00..777c16f 100644 --- a/ir_aarch64.dasc +++ b/ir_aarch64.dasc @@ -982,9 +982,7 @@ binop_fp: } else if ((ir_op_flags[op_insn->op] & IR_OP_FLAG_COMMUTATIVE) && ctx->ir_base[op_insn->op2].op == IR_RLOAD && ctx->ir_base[op_insn->op2].op2 == insn->op3) { - ir_ref tmp = op_insn->op1; - op_insn->op1 = op_insn->op2; - op_insn->op2 = tmp; + SWAP_REFS(op_insn->op1, op_insn->op2); ctx->rules[insn->op2] = IR_FUSED | IR_BINOP_INT; ctx->rules[op_insn->op1] = IR_SKIPPED | IR_RLOAD; return IR_REG_BINOP_INT; diff --git a/ir_fold.h b/ir_fold.h index ffba25f..9d36bc7 100644 --- a/ir_fold.h +++ b/ir_fold.h @@ -2871,9 +2871,7 @@ IR_FOLD(MUL(_, _)) IR_FOLD_NAMED(swap_ops) { if (op1 < op2) { /* move lower ref to op2 */ - ir_ref tmp = op1; - op1 = op2; - op2 = tmp; + SWAP_REFS(op1, op2); IR_FOLD_RESTART; } IR_FOLD_NEXT; @@ -2883,9 +2881,7 @@ IR_FOLD(ADD_OV(_, _)) IR_FOLD(MUL_OV(_, _)) { if (op1 < op2) { /* move lower ref to op2 */ - ir_ref tmp = op1; - op1 = op2; - op2 = tmp; + SWAP_REFS(op1, op2); IR_FOLD_RESTART; } /* skip CSE ??? */ @@ -2954,9 +2950,7 @@ IR_FOLD(GT(_, _)) IR_FOLD_BOOL((opt ^ (opt >> 1)) & 1); } } else if (op1 < op2) { /* move lower ref to op2 */ - ir_ref tmp = op1; - op1 = op2; - op2 = tmp; + SWAP_REFS(op1, op2); opt ^= 3; /* [U]LT <-> [U]GT, [U]LE <-> [U]GE */ IR_FOLD_RESTART; } @@ -2972,9 +2966,7 @@ IR_FOLD(UGT(_, _)) /* a >= a => true (two low bits are differ) */ IR_FOLD_BOOL((opt ^ (opt >> 1)) & 1); } else if (op1 < op2) { /* move lower ref to op2 */ - ir_ref tmp = op1; - op1 = op2; - op2 = tmp; + SWAP_REFS(op1, op2); opt ^= 3; /* [U]LT <-> [U]GT, [U]LE <-> [U]GE */ } IR_FOLD_NEXT; diff --git a/ir_x86.dasc b/ir_x86.dasc index 66ca2ec..11ec467 100644 --- a/ir_x86.dasc +++ b/ir_x86.dasc @@ -1529,9 +1529,7 @@ static bool ir_match_try_fuse_load(ir_ctx *ctx, ir_ref ref, ir_ref root); static void ir_swap_ops(ir_insn *insn) { - ir_ref tmp = insn->op1; - insn->op1 = insn->op2; - insn->op2 = tmp; + SWAP_REFS(insn->op1, insn->op2); } static bool ir_match_try_revert_lea_to_add(ir_ctx *ctx, ir_ref ref) @@ -5744,12 +5742,9 @@ static ir_op ir_emit_cmp_fp_common(ir_ctx *ctx, ir_ref root, ir_ref cmp_ref, ir_ op2_reg = ctx->regs[cmp_ref][2]; if (op1_reg == IR_REG_NONE && op2_reg != IR_REG_NONE && (op == IR_EQ || op == IR_NE)) { - ir_ref tmp; ir_reg tmp_reg; - tmp = op1; - op1 = op2; - op2 = tmp; + SWAP_REFS(op1, op2); tmp_reg = op1_reg; op1_reg = op2_reg; op2_reg = tmp_reg;