Skip to content

Commit

Permalink
Use SWAP_REFS() macro
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Apr 24, 2024
1 parent 0554940 commit 3983e78
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
4 changes: 1 addition & 3 deletions ir_aarch64.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 4 additions & 12 deletions ir_fold.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ??? */
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions ir_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3983e78

Please sign in to comment.