@@ -1010,6 +1010,7 @@ const char *ir_reg_name(int8_t reg, ir_type type)
1010
1010
_(MOD_PWR2) \
1011
1011
_(SDIV_PWR2) \
1012
1012
_(SMOD_PWR2) \
1013
+ _(BOOL_NOT) \
1013
1014
_(BOOL_NOT_INT) \
1014
1015
_(ABS_INT) \
1015
1016
_(OP_INT) \
@@ -2223,10 +2224,16 @@ binop_fp:
2223
2224
ir_match_fuse_load(ctx, insn->op2, ref);
2224
2225
return IR_MOD_INT;
2225
2226
case IR_BSWAP:
2227
+ IR_ASSERT(IR_IS_TYPE_INT(insn->type));
2228
+ return IR_OP_INT;
2226
2229
case IR_NOT:
2227
2230
if (insn->type == IR_BOOL) {
2228
- IR_ASSERT(IR_IS_TYPE_INT(ctx->ir_base[insn->op1].type)); // TODO: IR_BOOL_NOT_FP
2229
- return IR_BOOL_NOT_INT;
2231
+ if (ctx->ir_base[insn->op1].type == IR_BOOL) {
2232
+ return IR_BOOL_NOT;
2233
+ } else {
2234
+ IR_ASSERT(IR_IS_TYPE_INT(ctx->ir_base[insn->op1].type)); // TODO: IR_BOOL_NOT_FP
2235
+ return IR_BOOL_NOT_INT;
2236
+ }
2230
2237
} else {
2231
2238
IR_ASSERT(IR_IS_TYPE_INT(insn->type));
2232
2239
return IR_OP_INT;
@@ -5054,6 +5061,33 @@ static void ir_emit_abs_int(ir_ctx *ctx, ir_ref def, ir_insn *insn)
5054
5061
}
5055
5062
}
5056
5063
5064
+ static void ir_emit_bool_not(ir_ctx *ctx, ir_ref def, ir_insn *insn)
5065
+ {
5066
+ ir_backend_data *data = ctx->data;
5067
+ dasm_State **Dst = &data->dasm_state;
5068
+ ir_type type = ctx->ir_base[insn->op1].type;
5069
+ ir_ref op1 = insn->op1;
5070
+ ir_reg def_reg = IR_REG_NUM(ctx->regs[def][0]);
5071
+ ir_reg op1_reg = ctx->regs[def][1];
5072
+
5073
+ IR_ASSERT(def_reg != IR_REG_NONE);
5074
+
5075
+ if (op1_reg != IR_REG_NONE && IR_REG_SPILLED(op1_reg)) {
5076
+ op1_reg = IR_REG_NUM(op1_reg);
5077
+ ir_emit_load(ctx, type, op1_reg, op1);
5078
+ }
5079
+
5080
+ if (def_reg != op1_reg) {
5081
+ | mov Rb(def_reg), Rb(op1_reg)
5082
+ }
5083
+
5084
+ | xor Rb(def_reg), 1
5085
+
5086
+ if (IR_REG_SPILLED(ctx->regs[def][0])) {
5087
+ ir_emit_store(ctx, type, def, def_reg);
5088
+ }
5089
+ }
5090
+
5057
5091
static void ir_emit_bool_not_int(ir_ctx *ctx, ir_ref def, ir_insn *insn)
5058
5092
{
5059
5093
ir_backend_data *data = ctx->data;
@@ -10602,6 +10636,9 @@ void *ir_emit_code(ir_ctx *ctx, size_t *size_ptr)
10602
10636
case IR_ABS_INT:
10603
10637
ir_emit_abs_int(ctx, i, insn);
10604
10638
break;
10639
+ case IR_BOOL_NOT:
10640
+ ir_emit_bool_not(ctx, i, insn);
10641
+ break;
10605
10642
case IR_BOOL_NOT_INT:
10606
10643
ir_emit_bool_not_int(ctx, i, insn);
10607
10644
break;
0 commit comments