@@ -1010,6 +1010,7 @@ const char *ir_reg_name(int8_t reg, ir_type type)
10101010 _(MOD_PWR2) \
10111011 _(SDIV_PWR2) \
10121012 _(SMOD_PWR2) \
1013+ _(BOOL_NOT) \
10131014 _(BOOL_NOT_INT) \
10141015 _(ABS_INT) \
10151016 _(OP_INT) \
@@ -2223,10 +2224,16 @@ binop_fp:
22232224 ir_match_fuse_load(ctx, insn->op2, ref);
22242225 return IR_MOD_INT;
22252226 case IR_BSWAP:
2227+ IR_ASSERT(IR_IS_TYPE_INT(insn->type));
2228+ return IR_OP_INT;
22262229 case IR_NOT:
22272230 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+ }
22302237 } else {
22312238 IR_ASSERT(IR_IS_TYPE_INT(insn->type));
22322239 return IR_OP_INT;
@@ -5054,6 +5061,33 @@ static void ir_emit_abs_int(ir_ctx *ctx, ir_ref def, ir_insn *insn)
50545061 }
50555062}
50565063
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+
50575091static void ir_emit_bool_not_int(ir_ctx *ctx, ir_ref def, ir_insn *insn)
50585092{
50595093 ir_backend_data *data = ctx->data;
@@ -10602,6 +10636,9 @@ void *ir_emit_code(ir_ctx *ctx, size_t *size_ptr)
1060210636 case IR_ABS_INT:
1060310637 ir_emit_abs_int(ctx, i, insn);
1060410638 break;
10639+ case IR_BOOL_NOT:
10640+ ir_emit_bool_not(ctx, i, insn);
10641+ break;
1060510642 case IR_BOOL_NOT_INT:
1060610643 ir_emit_bool_not_int(ctx, i, insn);
1060710644 break;
0 commit comments