From bc407ced89e9b2a5005ffbdb1756c1fafe93f068 Mon Sep 17 00:00:00 2001 From: Mike Danes Date: Thu, 21 Sep 2017 22:50:16 +0300 Subject: Don't early-propagate negative array lengths There's no need for that and if the negative array length is not representable in 32 bit we'll end up producing a GT_CNS_INT node that has TYP_INT and a 64 bit value. That's because the original type (always TYP_INT) of the GT_ARR_LENGTH is preserved when changing the node to GT_CNS_INT. --- src/jit/earlyprop.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/jit/earlyprop.cpp') diff --git a/src/jit/earlyprop.cpp b/src/jit/earlyprop.cpp index d4d0e3ee41..50c696df97 100644 --- a/src/jit/earlyprop.cpp +++ b/src/jit/earlyprop.cpp @@ -289,9 +289,9 @@ bool Compiler::optEarlyPropRewriteTree(GenTreePtr tree) { assert(actualVal->IsCnsIntOrI()); - if (actualVal->gtIntCon.gtIconVal > INT32_MAX) + if ((actualVal->AsIntCon()->IconValue() < 0) || (actualVal->AsIntCon()->IconValue() > INT32_MAX)) { - // Don't propagate array lengths that are beyond the maximum value of a GT_ARR_LENGTH. + // Don't propagate array lengths that are beyond the maximum value of a GT_ARR_LENGTH or negative. // node. CORINFO_HELP_NEWARR_1_OBJ helper call allows to take a long integer as the // array length argument, but the type of GT_ARR_LENGTH is always INT32. return false; -- cgit v1.2.3