@@ -251,7 +251,7 @@ void RangeCheck::OptimizeRangeCheck(BasicBlock* block, Statement* stmt, GenTree*
251
251
{
252
252
JITDUMP (" Looking for array size assertions for: " FMT_VN " \n " , arrLenVn);
253
253
Range arrLength = Range (Limit (Limit::keDependent));
254
- MergeEdgeAssertions (m_pCompiler, arrLenVn, arrLenVn, block->bbAssertionIn , &arrLength);
254
+ MergeEdgeAssertions (arrLenVn, block->bbAssertionIn , &arrLength);
255
255
if (arrLength.lLimit .IsConstant ())
256
256
{
257
257
arrSize = arrLength.lLimit .GetConstant ();
@@ -640,28 +640,20 @@ void RangeCheck::MergeEdgeAssertions(GenTreeLclVarCommon* lcl, ASSERT_VALARG_TP
640
640
641
641
LclSsaVarDsc* ssaData = m_pCompiler->lvaGetDesc (lcl)->GetPerSsaData (lcl->GetSsaNum ());
642
642
ValueNum normalLclVN = m_pCompiler->vnStore ->VNConservativeNormalValue (ssaData->m_vnPair );
643
- ValueNum arrLenVN = m_pCompiler->vnStore ->VNConservativeNormalValue (m_pCurBndsChk->GetArrayLength ()->gtVNPair );
644
- MergeEdgeAssertions (m_pCompiler, normalLclVN, arrLenVN, assertions, pRange);
643
+ MergeEdgeAssertions (normalLclVN, assertions, pRange);
645
644
}
646
645
647
646
// ------------------------------------------------------------------------
648
647
// MergeEdgeAssertions: Merge assertions on the edge flowing into the block about a variable
649
648
//
650
649
// Arguments:
651
- // comp - the compiler instance
652
- // normalLclVN - the value number to look for assertions for
653
- // preferredBoundVN - when this VN is set, it will be given preference over constant limits
654
- // assertions - the assertions to use
655
- // pRange - the range to tighten with assertions
650
+ // normalLclVN - the value number to look for assertions for
651
+ // assertions - the assertions to use
652
+ // pRange - the range to tighten with assertions
656
653
//
657
- void RangeCheck::MergeEdgeAssertions (Compiler* comp,
658
- ValueNum normalLclVN,
659
- ValueNum preferredBoundVN,
660
- ASSERT_VALARG_TP assertions,
661
- Range* pRange,
662
- bool log)
654
+ void RangeCheck::MergeEdgeAssertions (ValueNum normalLclVN, ASSERT_VALARG_TP assertions, Range* pRange)
663
655
{
664
- if (BitVecOps::IsEmpty (comp ->apTraits , assertions))
656
+ if (BitVecOps::IsEmpty (m_pCompiler ->apTraits , assertions))
665
657
{
666
658
return ;
667
659
}
@@ -671,14 +663,14 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
671
663
return ;
672
664
}
673
665
674
- // Walk through the "assertions" to check if they apply.
675
- BitVecOps::Iter iter (comp ->apTraits , assertions);
666
+ // Walk through the "assertions" to check if the apply.
667
+ BitVecOps::Iter iter (m_pCompiler ->apTraits , assertions);
676
668
unsigned index = 0 ;
677
669
while (iter.NextElem (&index ))
678
670
{
679
671
AssertionIndex assertionIndex = GetAssertionIndex (index );
680
672
681
- Compiler::AssertionDsc* curAssertion = comp ->optGetAssertion (assertionIndex);
673
+ Compiler::AssertionDsc* curAssertion = m_pCompiler ->optGetAssertion (assertionIndex);
682
674
683
675
Limit limit (Limit::keUndef);
684
676
genTreeOps cmpOper = GT_NONE;
@@ -691,7 +683,7 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
691
683
ValueNumStore::CompareCheckedBoundArithInfo info;
692
684
693
685
// Get i, len, cns and < as "info."
694
- comp ->vnStore ->GetCompareCheckedBoundArithInfo (curAssertion->op1 .vn , &info);
686
+ m_pCompiler ->vnStore ->GetCompareCheckedBoundArithInfo (curAssertion->op1 .vn , &info);
695
687
696
688
// If we don't have the same variable we are comparing against, bail.
697
689
if (normalLclVN != info.cmpOp )
@@ -705,12 +697,12 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
705
697
}
706
698
707
699
// If the operand that operates on the bound is not constant, then done.
708
- if (!comp ->vnStore ->IsVNInt32Constant (info.arrOp ))
700
+ if (!m_pCompiler ->vnStore ->IsVNInt32Constant (info.arrOp ))
709
701
{
710
702
continue ;
711
703
}
712
704
713
- int cons = comp ->vnStore ->ConstantValue <int >(info.arrOp );
705
+ int cons = m_pCompiler ->vnStore ->ConstantValue <int >(info.arrOp );
714
706
limit = Limit (Limit::keBinOpArray, info.vnBound , info.arrOper == GT_SUB ? -cons : cons);
715
707
cmpOper = (genTreeOps)info.cmpOper ;
716
708
}
@@ -720,7 +712,7 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
720
712
ValueNumStore::CompareCheckedBoundArithInfo info;
721
713
722
714
// Get the info as "i", "<" and "len"
723
- comp ->vnStore ->GetCompareCheckedBound (curAssertion->op1 .vn , &info);
715
+ m_pCompiler ->vnStore ->GetCompareCheckedBound (curAssertion->op1 .vn , &info);
724
716
725
717
// If we don't have the same variable we are comparing against, bail.
726
718
if (normalLclVN == info.cmpOp )
@@ -744,7 +736,7 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
744
736
ValueNumStore::ConstantBoundInfo info;
745
737
746
738
// Get the info as "i", "<" and "100"
747
- comp ->vnStore ->GetConstantBoundInfo (curAssertion->op1 .vn , &info);
739
+ m_pCompiler ->vnStore ->GetConstantBoundInfo (curAssertion->op1 .vn , &info);
748
740
749
741
// If we don't have the same variable we are comparing against, bail.
750
742
if (normalLclVN != info.cmpOpVN )
@@ -764,10 +756,10 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
764
756
continue ;
765
757
}
766
758
767
- int cnstLimit = comp ->vnStore ->CoercedConstantValue <int >(curAssertion->op2 .vn );
759
+ int cnstLimit = m_pCompiler ->vnStore ->CoercedConstantValue <int >(curAssertion->op2 .vn );
768
760
769
761
if ((cnstLimit == 0 ) && (curAssertion->assertionKind == Compiler::OAK_NOT_EQUAL) &&
770
- comp ->vnStore ->IsVNCheckedBound (curAssertion->op1 .vn ))
762
+ m_pCompiler ->vnStore ->IsVNCheckedBound (curAssertion->op1 .vn ))
771
763
{
772
764
// we have arr.Len != 0, so the length must be atleast one
773
765
limit = Limit (Limit::keConstant, 1 );
@@ -812,31 +804,31 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
812
804
813
805
// Make sure the assertion is of the form != 0 or == 0 if it isn't a constant assertion.
814
806
if (!isConstantAssertion && (curAssertion->assertionKind != Compiler::OAK_NO_THROW) &&
815
- (curAssertion->op2 .vn != comp ->vnStore ->VNZeroForType (TYP_INT)))
807
+ (curAssertion->op2 .vn != m_pCompiler ->vnStore ->VNZeroForType (TYP_INT)))
816
808
{
817
809
continue ;
818
810
}
819
811
#ifdef DEBUG
820
- if (comp ->verbose )
812
+ if (m_pCompiler ->verbose )
821
813
{
822
- comp ->optPrintAssertion (curAssertion, assertionIndex);
814
+ m_pCompiler ->optPrintAssertion (curAssertion, assertionIndex);
823
815
}
824
816
#endif
825
817
826
818
// Limits are sometimes made with the form vn + constant, where vn is a known constant
827
819
// see if we can simplify this to just a constant
828
- if (limit.IsBinOpArray () && comp ->vnStore ->IsVNInt32Constant (limit.vn ))
820
+ if (limit.IsBinOpArray () && m_pCompiler ->vnStore ->IsVNInt32Constant (limit.vn ))
829
821
{
830
- Limit tempLimit = Limit (Limit::keConstant, comp ->vnStore ->ConstantValue <int >(limit.vn ));
822
+ Limit tempLimit = Limit (Limit::keConstant, m_pCompiler ->vnStore ->ConstantValue <int >(limit.vn ));
831
823
if (tempLimit.AddConstant (limit.cns ))
832
824
{
833
825
limit = tempLimit;
834
826
}
835
827
}
836
828
837
- ValueNum arrLenVN = preferredBoundVN ;
829
+ ValueNum arrLenVN = m_pCompiler-> vnStore -> VNConservativeNormalValue (m_pCurBndsChk-> GetArrayLength ()-> gtVNPair ) ;
838
830
839
- if (comp ->vnStore ->IsVNConstant (arrLenVN))
831
+ if (m_pCompiler ->vnStore ->IsVNConstant (arrLenVN))
840
832
{
841
833
// Set arrLenVN to NoVN; this will make it match the "vn" recorded on
842
834
// constant limits (where we explicitly track the constant and don't
@@ -925,10 +917,7 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
925
917
926
918
if (limit.vn != arrLenVN)
927
919
{
928
- if (log )
929
- {
930
- JITDUMP (" Array length VN did not match arrLen=" FMT_VN " , limit=" FMT_VN " \n " , arrLenVN, limit.vn );
931
- }
920
+ JITDUMP (" Array length VN did not match arrLen=" FMT_VN " , limit=" FMT_VN " \n " , arrLenVN, limit.vn );
932
921
continue ;
933
922
}
934
923
@@ -938,10 +927,7 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
938
927
// Incoming limit doesn't tighten the existing upper limit.
939
928
if (limCns >= curCns)
940
929
{
941
- if (log )
942
- {
943
- JITDUMP (" Bound limit %d doesn't tighten current bound %d\n " , limCns, curCns);
944
- }
930
+ JITDUMP (" Bound limit %d doesn't tighten current bound %d\n " , limCns, curCns);
945
931
continue ;
946
932
}
947
933
}
@@ -968,12 +954,8 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
968
954
969
955
case GT_GT:
970
956
case GT_GE:
971
- // GT/GE being unsigned creates a non-contiguous range which we can't represent
972
- // using single Range object.
973
- if (!isUnsigned)
974
- {
975
- pRange->lLimit = limit;
976
- }
957
+ pRange->lLimit = limit;
958
+ // it doesn't matter if it's isUnsigned or not here - it's not negative anyway.
977
959
break ;
978
960
979
961
case GT_EQ:
@@ -985,13 +967,9 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
985
967
// All other 'cmpOper' kinds leave lLimit/uLimit unchanged
986
968
break ;
987
969
}
988
-
989
- if (log )
990
- {
991
- JITDUMP (" The range after edge merging:" );
992
- JITDUMP (pRange->ToString (comp));
993
- JITDUMP (" \n " );
994
- }
970
+ JITDUMP (" The range after edge merging:" );
971
+ JITDUMP (pRange->ToString (m_pCompiler));
972
+ JITDUMP (" \n " );
995
973
}
996
974
}
997
975
0 commit comments