Fixed crash on dead PHI

This commit is contained in:
Dmitry Stogov 2023-10-12 14:54:23 +03:00
parent 3f728b61b9
commit 1970a16496
4 changed files with 116 additions and 0 deletions

View File

@ -790,6 +790,10 @@ int ir_compute_live_ranges(ir_ctx *ctx)
ir_bitset_excl(live, v);
/* PHIs inputs must not be processed */
ival = ctx->live_intervals[v];
if (UNEXPECTED(!ival)) {
/* Dead PHI */
ival = ir_add_live_range(ctx, v, IR_DEF_LIVE_POS_FROM_REF(ref), IR_USE_LIVE_POS_FROM_REF(ref));
}
ival->type = insn->type;
ir_add_use(ctx, ival, 0, IR_DEF_LIVE_POS_FROM_REF(ref), IR_REG_NONE, IR_USE_SHOULD_BE_IN_REG, 0);
continue;
@ -1397,6 +1401,10 @@ int ir_compute_live_ranges(ir_ctx *ctx)
} else {
/* PHIs inputs must not be processed */
ival = ctx->live_intervals[v];
if (UNEXPECTED(!ival)) {
/* Dead PHI */
ival = ir_add_live_range(ctx, v, IR_DEF_LIVE_POS_FROM_REF(ref), IR_USE_LIVE_POS_FROM_REF(ref));
}
ival->type = insn->type;
ir_add_use(ctx, ival, 0, IR_DEF_LIVE_POS_FROM_REF(ref), IR_REG_NONE, IR_USE_SHOULD_BE_IN_REG, 0);
continue;

37
tests/dead_phi_001.irt Normal file
View File

@ -0,0 +1,37 @@
--TEST--
001: Dead phi -O0
--ARGS--
-O0 --save
--CODE--
{
l_1 = START(l_12);
int32_t d_2 = PARAM(l_1, "x", 0);
int32_t d_3 = PARAM(l_1, "y", 1);
l_4 = IF(l_1, d_2);
l_5 = IF_TRUE(l_4);
l_6 = END(l_5);
l_7 = IF_FALSE(l_4);
l_8 = END(l_7);
l_9 = MERGE(l_6, l_8);
int32_t d_10 = PHI(l_9, d_2, d_3);
int32_t d_11 = NOT(d_10);
l_12 = RETURN(l_9);
}
--EXPECT--
{
uintptr_t c_1 = 0;
bool c_2 = 0;
bool c_3 = 1;
l_1 = START(l_12);
int32_t d_2 = PARAM(l_1, "x", 0);
int32_t d_3 = PARAM(l_1, "y", 1);
l_4 = IF(l_1, d_2);
l_5 = IF_TRUE(l_4);
l_6 = END(l_5);
l_7 = IF_FALSE(l_4);
l_8 = END(l_7);
l_9 = MERGE(l_6, l_8);
int32_t d_10 = PHI(l_9, d_2, d_3);
int32_t d_11 = NOT(d_10);
l_12 = RETURN(l_9, null);
}

36
tests/dead_phi_002.irt Normal file
View File

@ -0,0 +1,36 @@
--TEST--
002: Dead phi -O1
--ARGS--
-O1 --save
--CODE--
{
l_1 = START(l_12);
int32_t d_2 = PARAM(l_1, "x", 0);
int32_t d_3 = PARAM(l_1, "y", 1);
l_4 = IF(l_1, d_2);
l_5 = IF_TRUE(l_4);
l_6 = END(l_5);
l_7 = IF_FALSE(l_4);
l_8 = END(l_7);
l_9 = MERGE(l_6, l_8);
int32_t d_10 = PHI(l_9, d_2, d_3);
int32_t d_11 = NOT(d_10);
l_12 = RETURN(l_9);
}
--EXPECT--
{
uintptr_t c_1 = 0;
bool c_2 = 0;
bool c_3 = 1;
l_1 = START(l_11);
int32_t d_2 = PARAM(l_1, "x", 0);
int32_t d_3 = PARAM(l_1, "y", 1);
l_4 = IF(l_1, d_2);
l_5 = IF_TRUE(l_4);
l_6 = END(l_5);
l_7 = IF_FALSE(l_4);
l_8 = END(l_7);
l_9 = MERGE(l_6, l_8);
int32_t d_10 = PHI(l_9, d_2, d_3);
l_11 = RETURN(l_9, null);
}

35
tests/dead_phi_003.irt Normal file
View File

@ -0,0 +1,35 @@
--TEST--
003: Dead phi -O2
--ARGS--
-O2 --save
--CODE--
{
l_1 = START(l_12);
int32_t d_2 = PARAM(l_1, "x", 0);
int32_t d_3 = PARAM(l_1, "y", 1);
l_4 = IF(l_1, d_2);
l_5 = IF_TRUE(l_4);
l_6 = END(l_5);
l_7 = IF_FALSE(l_4);
l_8 = END(l_7);
l_9 = MERGE(l_6, l_8);
int32_t d_10 = PHI(l_9, d_2, d_3);
int32_t d_11 = NOT(d_10);
l_12 = RETURN(l_9);
}
--EXPECT--
{
uintptr_t c_1 = 0;
bool c_2 = 0;
bool c_3 = 1;
l_1 = START(l_10);
int32_t d_2 = PARAM(l_1, "x", 0);
int32_t d_3 = PARAM(l_1, "y", 1);
l_4 = IF(l_1, d_2);
l_5 = IF_TRUE(l_4);
l_6 = END(l_5);
l_7 = IF_FALSE(l_4);
l_8 = END(l_7);
l_9 = MERGE(l_6, l_8);
l_10 = RETURN(l_9, null);
}