Fixed non-boolean constant GUARD condition checks

This commit is contained in:
Dmitry Stogov 2023-06-29 23:49:20 +03:00
parent 7058c41411
commit ce2d6ceba6
3 changed files with 18 additions and 4 deletions

View File

@ -3956,8 +3956,9 @@ static void ir_emit_guard(ir_ctx *ctx, ir_ref def, ir_insn *insn)
IR_ASSERT(IR_IS_TYPE_INT(type)); IR_ASSERT(IR_IS_TYPE_INT(type));
if (IR_IS_CONST_REF(insn->op2)) { if (IR_IS_CONST_REF(insn->op2)) {
if ((insn->op == IR_GUARD && insn->op2 == IR_FALSE) || bool is_true = ir_ref_is_true(ctx, insn->op2);
(insn->op == IR_GUARD_NOT && insn->op2 == IR_TRUE)) {
if ((insn->op == IR_GUARD && !is_true) || (insn->op == IR_GUARD_NOT && is_true)) {
if (IR_IS_CONST_REF(insn->op3)) { if (IR_IS_CONST_REF(insn->op3)) {
void *addr = ir_jmp_addr(ctx, insn, &ctx->ir_base[insn->op3]); void *addr = ir_jmp_addr(ctx, insn, &ctx->ir_base[insn->op3]);

View File

@ -773,6 +773,18 @@ IR_ALWAYS_INLINE bool ir_const_is_true(const ir_insn *v)
return 0; return 0;
} }
IR_ALWAYS_INLINE bool ir_ref_is_true(ir_ctx *ctx, ir_ref ref)
{
if (ref == IR_TRUE) {
return 1;
} else if (ref == IR_FALSE) {
return 0;
} else {
IR_ASSERT(IR_IS_CONST_REF(ref));
return ir_const_is_true(&ctx->ir_base[ref]);
}
}
/* IR OP flags */ /* IR OP flags */
#define IR_OP_FLAG_OPERANDS_SHIFT 3 #define IR_OP_FLAG_OPERANDS_SHIFT 3

View File

@ -6840,8 +6840,9 @@ static bool ir_emit_guard(ir_ctx *ctx, uint32_t b, ir_ref def, ir_insn *insn)
IR_ASSERT(IR_IS_TYPE_INT(type)); IR_ASSERT(IR_IS_TYPE_INT(type));
if (IR_IS_CONST_REF(insn->op2)) { if (IR_IS_CONST_REF(insn->op2)) {
if ((insn->op == IR_GUARD && insn->op2 == IR_FALSE) || bool is_true = ir_ref_is_true(ctx, insn->op2);
(insn->op == IR_GUARD_NOT && insn->op2 == IR_TRUE)) {
if ((insn->op == IR_GUARD && !is_true) || (insn->op == IR_GUARD_NOT && is_true)) {
addr = ir_jmp_addr(ctx, insn, &ctx->ir_base[insn->op3]); addr = ir_jmp_addr(ctx, insn, &ctx->ir_base[insn->op3]);
if (sizeof(void*) == 4 || IR_MAY_USE_32BIT_ADDR(addr)) { if (sizeof(void*) == 4 || IR_MAY_USE_32BIT_ADDR(addr)) {
| jmp aword &addr | jmp aword &addr