From 447840e07c2888803d616eec4bde098356a49540 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 11 Aug 2025 16:52:51 +0200 Subject: [PATCH] JIT: Avoid creating impossible equality assertions Fix #113940 --- src/coreclr/jit/assertionprop.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index 851b23366ce163..c30f63f7be3281 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -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(iconVal));