Skip to content

JIT: Avoid creating impossible equality assertions #118586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,9 +1232,18 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1, GenTree* op2, optAsser
if (op2->OperIs(GT_CNS_INT))
{
ssize_t iconVal = op2->AsIntCon()->IconValue();
if (varTypeIsSmall(lclVar) && op1->OperIs(GT_STORE_LCL_VAR))
if (varTypeIsSmall(lclVar))
{
iconVal = optCastConstantSmall(iconVal, lclVar->TypeGet());
ssize_t truncatedIconVal = optCastConstantSmall(iconVal, lclVar->TypeGet());
if (!op1->OperIs(GT_STORE_LCL_VAR) && (truncatedIconVal != iconVal))
{
// This assertion would be saying that a small local is equal to a value
// outside its range. It means this block is unreachable. Avoid creating
// such impossible assertions which can hit assertions in other places.
goto DONE_ASSERTION;
}

iconVal = truncatedIconVal;
if (!optLocalAssertionProp)
{
assertion.op2.vn = vnStore->VNForIntCon(static_cast<int>(iconVal));
Expand Down
Loading