summaryrefslogtreecommitdiff
path: root/src/jit
diff options
context:
space:
mode:
authorBrian Sullivan <briansul@microsoft.com>2019-06-19 11:18:02 -0700
committerBrian Sullivan <briansul@microsoft.com>2019-06-19 13:34:25 -0700
commitd4fd282d4b3d2190f0350a2f1f92c188f0073017 (patch)
tree7271cdd3e5c6d43f1d6a90184872d1209cedc185 /src/jit
parentd10701cc4d591bc89697b7bab98553305dcc9df4 (diff)
downloadcoreclr-d4fd282d4b3d2190f0350a2f1f92c188f0073017.tar.gz
coreclr-d4fd282d4b3d2190f0350a2f1f92c188f0073017.tar.bz2
coreclr-d4fd282d4b3d2190f0350a2f1f92c188f0073017.zip
Fix Issue #25134 - AssertionProp incorrectly removes cast from uint
Add additional check for the GT_UNSIGNED flag + Ran clang-format + Code review feedback, use IsUnsigned()
Diffstat (limited to 'src/jit')
-rw-r--r--src/jit/assertionprop.cpp36
-rw-r--r--src/jit/compiler.h5
-rw-r--r--src/jit/morph.cpp2
3 files changed, 33 insertions, 10 deletions
diff --git a/src/jit/assertionprop.cpp b/src/jit/assertionprop.cpp
index 5b62e88303..ae73c8800b 100644
--- a/src/jit/assertionprop.cpp
+++ b/src/jit/assertionprop.cpp
@@ -2213,13 +2213,16 @@ AssertionIndex Compiler::optFindComplementary(AssertionIndex assertIndex)
/*****************************************************************************
*
- * Given a lclNum and a toType, return assertion index of the assertion that
- * claims that a variable's value is always a valid subrange of toType.
- * Thus we can discard or omit a cast to toType. Returns NO_ASSERTION_INDEX
+ * Given a lclNum, a fromType and a toType, return assertion index of the assertion that
+ * claims that a variable's value is always a valid subrange of the formType.
+ * Thus we can discard or omit a cast to fromType. Returns NO_ASSERTION_INDEX
* if one such assertion could not be found in "assertions."
*/
-AssertionIndex Compiler::optAssertionIsSubrange(GenTree* tree, var_types toType, ASSERT_VALARG_TP assertions)
+AssertionIndex Compiler::optAssertionIsSubrange(GenTree* tree,
+ var_types fromType,
+ var_types toType,
+ ASSERT_VALARG_TP assertions)
{
if (!optLocalAssertionProp && BitVecOps::IsEmpty(apTraits, assertions))
{
@@ -2243,6 +2246,16 @@ AssertionIndex Compiler::optAssertionIsSubrange(GenTree* tree, var_types toType,
continue;
}
+ // If we have an unsigned fromType, then the loBound can't be negative
+ //
+ if (varTypeIsUnsigned(fromType))
+ {
+ if (curAssertion->op2.u2.loBound < 0)
+ {
+ continue;
+ }
+ }
+
// Make sure the toType is within current assertion's bounds.
switch (toType)
{
@@ -3384,11 +3397,18 @@ GenTree* Compiler::optAssertionProp_Cast(ASSERT_VALARG_TP assertions, GenTree* t
{
assert(tree->gtOper == GT_CAST);
- var_types toType = tree->gtCast.gtCastType;
- GenTree* op1 = tree->gtCast.CastOp();
+ var_types fromType = tree->CastFromType();
+ var_types toType = tree->gtCast.gtCastType;
+ GenTree* op1 = tree->gtCast.CastOp();
+
+ // force the fromType to unsigned if GT_UNSIGNED flag is set
+ if (tree->IsUnsigned())
+ {
+ fromType = genUnsignedType(fromType);
+ }
// If we have a cast involving floating point types, then bail.
- if (varTypeIsFloating(toType) || varTypeIsFloating(op1->TypeGet()))
+ if (varTypeIsFloating(toType) || varTypeIsFloating(fromType))
{
return nullptr;
}
@@ -3406,7 +3426,7 @@ GenTree* Compiler::optAssertionProp_Cast(ASSERT_VALARG_TP assertions, GenTree* t
return nullptr;
}
- AssertionIndex index = optAssertionIsSubrange(lcl, toType, assertions);
+ AssertionIndex index = optAssertionIsSubrange(lcl, fromType, toType, assertions);
if (index != NO_ASSERTION_INDEX)
{
LclVarDsc* varDsc = &lvaTable[lcl->gtLclVarCommon.gtLclNum];
diff --git a/src/jit/compiler.h b/src/jit/compiler.h
index bdc9a5c262..90aec385b6 100644
--- a/src/jit/compiler.h
+++ b/src/jit/compiler.h
@@ -6667,7 +6667,10 @@ public:
ASSERT_TP optGetVnMappedAssertions(ValueNum vn);
// Used for respective assertion propagations.
- AssertionIndex optAssertionIsSubrange(GenTree* tree, var_types toType, ASSERT_VALARG_TP assertions);
+ AssertionIndex optAssertionIsSubrange(GenTree* tree,
+ var_types fromType,
+ var_types toType,
+ ASSERT_VALARG_TP assertions);
AssertionIndex optAssertionIsSubtype(GenTree* tree, GenTree* methodTableArg, ASSERT_VALARG_TP assertions);
AssertionIndex optAssertionIsNonNullInternal(GenTree* op, ASSERT_VALARG_TP assertions);
bool optAssertionIsNonNull(GenTree* op,
diff --git a/src/jit/morph.cpp b/src/jit/morph.cpp
index 5c13c2bc1a..610bd17805 100644
--- a/src/jit/morph.cpp
+++ b/src/jit/morph.cpp
@@ -6084,7 +6084,7 @@ GenTree* Compiler::fgMorphLocalVar(GenTree* tree, bool forceRemorph)
{
#if LOCAL_ASSERTION_PROP
/* Assertion prop can tell us to omit adding a cast here */
- if (optLocalAssertionProp && optAssertionIsSubrange(tree, varType, apFull) != NO_ASSERTION_INDEX)
+ if (optLocalAssertionProp && optAssertionIsSubrange(tree, TYP_INT, varType, apFull) != NO_ASSERTION_INDEX)
{
return tree;
}