diff --git a/ir_aarch64.dasc b/ir_aarch64.dasc index 5a8dba1..94c95d6 100644 --- a/ir_aarch64.dasc +++ b/ir_aarch64.dasc @@ -716,6 +716,8 @@ binop_fp: return IR_CALL; case IR_VAR: return IR_SKIPPED | IR_VAR; + case IR_PARAM: + return ctx->use_lists[ref].count > 0 ? IR_PARAM : IR_SKIPPED | IR_PARAM; case IR_ALLOCA: if (ctx->flags & IR_FUNCTION) { ctx->flags |= IR_USE_FRAME_POINTER | IR_HAS_ALLOCA; diff --git a/ir_ra.c b/ir_ra.c index 22fa88c..b534894 100644 --- a/ir_ra.c +++ b/ir_ra.c @@ -62,7 +62,7 @@ static int ir_assign_virtual_registers_slow(ir_ctx *ctx) insn += n; while (i < bb->end) { flags = ir_op_flags[insn->op]; - if (((flags & IR_OP_FLAG_DATA) && ctx->use_lists[i].count > 0) + if (((flags & IR_OP_FLAG_DATA) && insn->op != IR_VAR && (insn->op != IR_PARAM || ctx->use_lists[i].count > 0)) || ((flags & IR_OP_FLAG_MEM) && ctx->use_lists[i].count > 1)) { if (!ctx->rules || !(ctx->rules[i] & (IR_FUSED|IR_SKIPPED))) { vregs[i] = ++vregs_count; @@ -99,7 +99,7 @@ int ir_assign_virtual_registers(ir_ctx *ctx) if (ctx->rules[i] && !(ctx->rules[i] & (IR_FUSED|IR_SKIPPED))) { uint32_t flags = ir_op_flags[insn->op]; - if (((flags & IR_OP_FLAG_DATA) && ctx->use_lists[i].count > 0) + if ((flags & IR_OP_FLAG_DATA) || ((flags & IR_OP_FLAG_MEM) && ctx->use_lists[i].count > 1)) { v = ++vregs_count; } @@ -323,7 +323,7 @@ static ir_live_interval *ir_fix_live_range(ir_ctx *ctx, int v, ir_live_pos old_s p = p->next; } #endif - IR_ASSERT(p && p->start == old_start); + IR_ASSERT(ival && p->start == old_start); p->start = new_start; return ival; } diff --git a/ir_x86.dasc b/ir_x86.dasc index 3508e1d..43b66d2 100644 --- a/ir_x86.dasc +++ b/ir_x86.dasc @@ -1365,6 +1365,8 @@ binop_fp: return insn->op; case IR_VAR: return IR_SKIPPED | IR_VAR; + case IR_PARAM: + return ctx->use_lists[ref].count > 0 ? IR_PARAM : IR_SKIPPED | IR_PARAM; case IR_ALLOCA: /* alloca() may be use only in functions */ if (ctx->flags & IR_FUNCTION) { diff --git a/tests/bugs/gh-00033.irt b/tests/bugs/gh-00033.irt new file mode 100644 index 0000000..ae60593 --- /dev/null +++ b/tests/bugs/gh-00033.irt @@ -0,0 +1,28 @@ +--TEST-- +GH-33: IR program failed to compile with "-O0" "-S" options +--TARGET-- +x86_64 +--ARGS-- +-O0 -S +--CODE-- +{ + uintptr_t c_1 = 0; + bool c_2 = 0; + bool c_3 = 1; + int32_t c_4 = 10; + l_1 = START(l_4); + int32_t d_2 = PARAM(l_1, "x", 0); + int32_t d_3 = DIV(d_2, c_4); + l_4 = RETURN(l_1, null); +} +--EXPECT-- +test: + subq $8, %rsp + movl %edi, (%rsp) + movl (%rsp), %eax + movl $0xa, %ecx + cltd + idivl %ecx + movl %eax, 4(%rsp) + addq $8, %rsp + retq