Skip to content

Commit 0bdce45

Browse files
authored
JIT: Avoid creating impossible equality assertions (#118586)
Fix #113940
1 parent 6531acf commit 0bdce45

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/coreclr/jit/assertionprop.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,9 +1232,18 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1, GenTree* op2, optAsser
12321232
if (op2->OperIs(GT_CNS_INT))
12331233
{
12341234
ssize_t iconVal = op2->AsIntCon()->IconValue();
1235-
if (varTypeIsSmall(lclVar) && op1->OperIs(GT_STORE_LCL_VAR))
1235+
if (varTypeIsSmall(lclVar))
12361236
{
1237-
iconVal = optCastConstantSmall(iconVal, lclVar->TypeGet());
1237+
ssize_t truncatedIconVal = optCastConstantSmall(iconVal, lclVar->TypeGet());
1238+
if (!op1->OperIs(GT_STORE_LCL_VAR) && (truncatedIconVal != iconVal))
1239+
{
1240+
// This assertion would be saying that a small local is equal to a value
1241+
// outside its range. It means this block is unreachable. Avoid creating
1242+
// such impossible assertions which can hit assertions in other places.
1243+
goto DONE_ASSERTION;
1244+
}
1245+
1246+
iconVal = truncatedIconVal;
12381247
if (!optLocalAssertionProp)
12391248
{
12401249
assertion.op2.vn = vnStore->VNForIntCon(static_cast<int>(iconVal));

0 commit comments

Comments
 (0)