Fixed GH issue #33: IR program failed to compile with "-O0" "-S" options

This commit is contained in:
Dmitry Stogov 2023-06-05 18:22:12 +03:00
parent b5bb5f869a
commit 186dc6b0a6
4 changed files with 35 additions and 3 deletions

View File

@ -716,6 +716,8 @@ binop_fp:
return IR_CALL; return IR_CALL;
case IR_VAR: case IR_VAR:
return IR_SKIPPED | 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: case IR_ALLOCA:
if (ctx->flags & IR_FUNCTION) { if (ctx->flags & IR_FUNCTION) {
ctx->flags |= IR_USE_FRAME_POINTER | IR_HAS_ALLOCA; ctx->flags |= IR_USE_FRAME_POINTER | IR_HAS_ALLOCA;

View File

@ -62,7 +62,7 @@ static int ir_assign_virtual_registers_slow(ir_ctx *ctx)
insn += n; insn += n;
while (i < bb->end) { while (i < bb->end) {
flags = ir_op_flags[insn->op]; 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)) { || ((flags & IR_OP_FLAG_MEM) && ctx->use_lists[i].count > 1)) {
if (!ctx->rules || !(ctx->rules[i] & (IR_FUSED|IR_SKIPPED))) { if (!ctx->rules || !(ctx->rules[i] & (IR_FUSED|IR_SKIPPED))) {
vregs[i] = ++vregs_count; 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))) { if (ctx->rules[i] && !(ctx->rules[i] & (IR_FUSED|IR_SKIPPED))) {
uint32_t flags = ir_op_flags[insn->op]; 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)) { || ((flags & IR_OP_FLAG_MEM) && ctx->use_lists[i].count > 1)) {
v = ++vregs_count; 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; p = p->next;
} }
#endif #endif
IR_ASSERT(p && p->start == old_start); IR_ASSERT(ival && p->start == old_start);
p->start = new_start; p->start = new_start;
return ival; return ival;
} }

View File

@ -1365,6 +1365,8 @@ binop_fp:
return insn->op; return insn->op;
case IR_VAR: case IR_VAR:
return IR_SKIPPED | 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: case IR_ALLOCA:
/* alloca() may be use only in functions */ /* alloca() may be use only in functions */
if (ctx->flags & IR_FUNCTION) { if (ctx->flags & IR_FUNCTION) {

28
tests/bugs/gh-00033.irt Normal file
View File

@ -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