Skip to content

Commit e9d9995

Browse files
authored
Fix IsVNConstantBound assert (#114486)
1 parent 9d2b23b commit e9d9995

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/coreclr/jit/assertionprop.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5675,25 +5675,27 @@ bool Compiler::optCreateJumpTableImpliedAssertions(BasicBlock* switchBb)
56755675
// default: %name.Length is >= 8 here%
56765676
// }
56775677
//
5678-
if (value > 0)
5678+
if ((value > 0) && !vnStore->IsVNConstant(opVN))
56795679
{
56805680
AssertionDsc dsc = {};
56815681
dsc.assertionKind = OAK_NOT_EQUAL;
56825682
dsc.op2.kind = O2K_CONST_INT;
56835683
dsc.op2.vn = vnStore->VNZeroForType(TYP_INT);
56845684
dsc.op2.u1.iconVal = 0;
56855685
dsc.op2.SetIconFlag(GTF_EMPTY);
5686-
if (vnStore->IsVNCheckedBound(opVN))
5686+
if (vnStore->IsVNNeverNegative(opVN))
56875687
{
5688-
// Create "arrBnd >= value" assertion
5688+
// Create "X >= value" assertion (both operands are never negative)
56895689
dsc.op1.kind = O1K_CONSTANT_LOOP_BND;
56905690
dsc.op1.vn = vnStore->VNForFunc(TYP_INT, VNF_GE, opVN, vnStore->VNForIntCon(value));
5691+
assert(vnStore->IsVNConstantBound(dsc.op1.vn));
56915692
}
56925693
else
56935694
{
56945695
// Create "X u>= value" assertion
56955696
dsc.op1.kind = O1K_CONSTANT_LOOP_BND_UN;
56965697
dsc.op1.vn = vnStore->VNForFunc(TYP_INT, VNF_GE_UN, opVN, vnStore->VNForIntCon(value));
5698+
assert(vnStore->IsVNConstantBoundUnsigned(dsc.op1.vn));
56975699
}
56985700
newAssertIdx = optAddAssertion(&dsc);
56995701
}

src/coreclr/jit/valuenum.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6923,6 +6923,9 @@ bool ValueNumStore::IsVNConstantBound(ValueNum vn)
69236923
{
69246924
const bool op1IsConst = IsVNInt32Constant(funcApp.m_args[0]);
69256925
const bool op2IsConst = IsVNInt32Constant(funcApp.m_args[1]);
6926+
6927+
// Technically, we can allow both to be constants,
6928+
// but such relops are expected to be constant folded anyway.
69266929
return op1IsConst != op2IsConst;
69276930
}
69286931
}
@@ -6940,6 +6943,8 @@ bool ValueNumStore::IsVNConstantBoundUnsigned(ValueNum vn)
69406943
case VNF_LE_UN:
69416944
case VNF_GE_UN:
69426945
case VNF_GT_UN:
6946+
// Technically, we can allow both to be constants,
6947+
// but such relops are expected to be constant folded anyway.
69436948
return IsVNPositiveInt32Constant(funcApp.m_args[0]) != IsVNPositiveInt32Constant(funcApp.m_args[1]);
69446949
default:
69456950
break;

0 commit comments

Comments
 (0)