@@ -1943,6 +1943,28 @@ void Compiler::optCreateComplementaryAssertion(AssertionIndex assertionIndex,
19431943
19441944 if (candidateAssertion.assertionKind == OAK_EQUAL)
19451945 {
1946+ if (candidateAssertion.op1 .kind == O1K_LCLVAR)
1947+ {
1948+ // "LCLVAR != CNS" is not a useful assertion (unless CNS is 0)
1949+ if ((candidateAssertion.op2 .kind == O2K_CONST_INT || candidateAssertion.op2 .kind == O2K_CONST_LONG) &&
1950+ (candidateAssertion.op2 .u1 .iconVal != 0 ) && (candidateAssertion.op2 .u1 .iconVal != 1 ))
1951+ {
1952+ return ;
1953+ }
1954+
1955+ // "LCLVAR != LCLVAR_COPY"
1956+ if (candidateAssertion.op2 .kind == O2K_LCLVAR_COPY)
1957+ {
1958+ return ;
1959+ }
1960+ }
1961+
1962+ // "Object is not Class" is also not a useful assertion (at least for now)
1963+ if ((candidateAssertion.op1 .kind == O1K_EXACT_TYPE) || (candidateAssertion.op1 .kind == O1K_SUBTYPE))
1964+ {
1965+ return ;
1966+ }
1967+
19461968 AssertionIndex index = optCreateAssertion (op1, op2, OAK_NOT_EQUAL, helperCallArgs);
19471969 optMapComplementary (index, assertionIndex);
19481970 }
@@ -2238,18 +2260,24 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree)
22382260 if (con >= 0 )
22392261 {
22402262 AssertionDsc dsc;
2241-
2242- // For arr.Length != 0, we know that 0 is a valid index
2243- // For arr.Length == con, we know that con - 1 is the greatest valid index
2263+ bool useNextEdge;
22442264 if (con == 0 )
22452265 {
2266+ // arr.Length != 0 -> Then: idx = 0 Else: no assertion
2267+ // arr.Length == 0 -> Then: no assertion, Else: idx = 0
2268+ //
22462269 dsc.assertionKind = OAK_NOT_EQUAL;
22472270 dsc.op1 .bnd .vnIdx = vnStore->VNForIntCon (0 );
2271+ useNextEdge = relop->OperIs (GT_EQ);
22482272 }
22492273 else
22502274 {
2275+ // arr.Length == 10 -> Then: idx = [0..9], Else: no assertion
2276+ // arr.Length != 10 -> Then: no assertion, Else: idx = [0..9]
2277+ //
22512278 dsc.assertionKind = OAK_EQUAL;
22522279 dsc.op1 .bnd .vnIdx = vnStore->VNForIntCon (con - 1 );
2280+ useNextEdge = relop->OperIs (GT_NE);
22532281 }
22542282
22552283 dsc.op1 .vn = op1VN;
@@ -2263,14 +2291,7 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree)
22632291 // when con is not zero, create an assertion on the arr.Length == con edge
22642292 // when con is zero, create an assertion on the arr.Length != 0 edge
22652293 AssertionIndex index = optAddAssertion (&dsc);
2266- if (relop->OperIs (GT_NE) != (con == 0 ))
2267- {
2268- return AssertionInfo::ForNextEdge (index);
2269- }
2270- else
2271- {
2272- return index;
2273- }
2294+ return useNextEdge ? AssertionInfo::ForNextEdge (index) : index;
22742295 }
22752296 }
22762297 }
0 commit comments