@@ -651,14 +651,10 @@ bool RangeCheck::TryGetRangeFromAssertions(Compiler* comp, ValueNum num, ASSERT_
651
651
// assertions - the assertions to use
652
652
// pRange - the range to tighten with assertions
653
653
//
654
- void RangeCheck::MergeEdgeAssertions (Compiler* comp,
655
- ValueNum normalLclVN,
656
- ValueNum preferredBoundVN,
657
- ASSERT_VALARG_TP assertions,
658
- Range* pRange,
659
- bool log)
654
+ void RangeCheck::MergeEdgeAssertions (
655
+ Compiler* comp, ValueNum normalLclVN, ValueNum preferredBoundVN, ASSERT_VALARG_TP assertions, Range* pRange)
660
656
{
661
- Range range = Range (Limit (Limit::keDependent ));
657
+ Range assertedRange = Range (Limit (Limit::keUnknown ));
662
658
if (BitVecOps::IsEmpty (comp->apTraits , assertions))
663
659
{
664
660
return ;
@@ -903,10 +899,10 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
903
899
{
904
900
case GT_LT:
905
901
case GT_LE:
906
- range .uLimit = limit;
902
+ assertedRange .uLimit = limit;
907
903
if (isUnsigned)
908
904
{
909
- range .lLimit = Limit (Limit::keConstant, 0 );
905
+ assertedRange .lLimit = Limit (Limit::keConstant, 0 );
910
906
}
911
907
break ;
912
908
@@ -916,13 +912,13 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
916
912
// using single Range object.
917
913
if (!isUnsigned)
918
914
{
919
- range .lLimit = limit;
915
+ assertedRange .lLimit = limit;
920
916
}
921
917
break ;
922
918
923
919
case GT_EQ:
924
- range .uLimit = limit;
925
- range .lLimit = limit;
920
+ assertedRange .uLimit = limit;
921
+ assertedRange .lLimit = limit;
926
922
break ;
927
923
928
924
default :
@@ -931,31 +927,37 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
931
927
}
932
928
933
929
// We have two ranges - we need to merge (tighten) them.
930
+
934
931
auto tightenLimit = [](Limit l1, Limit l2, ValueNum preferredBound, bool isLower) -> Limit {
935
- // 1) if one the limits is completely unknown, use the other one.
936
- if (l1.IsUndef () || l1. IsUnknown () || l2.IsUndef () || l2. IsUnknown ())
932
+ // 1) One of the limits is undef, unknown or dependent
933
+ if (l1.IsUndef () || l2.IsUndef ())
937
934
{
938
- return (l1.IsUndef () || l1.IsUnknown ()) ? l2 : l1;
935
+ // Anything is better than undef.
936
+ return l1.IsUndef () ? l2 : l1;
937
+ }
938
+ if (l1.IsUnknown () || l2.IsUnknown ())
939
+ {
940
+ // Anything is better than unknown.
941
+ return l1.IsUnknown () ? l2 : l1;
939
942
}
940
-
941
- // 2) If one limit is dependent and the other is not, use the non-dependent one.
942
943
if (l1.IsDependent () || l2.IsDependent ())
943
944
{
945
+ // Anything is better than dependent.
944
946
return l1.IsDependent () ? l2 : l1;
945
947
}
946
948
947
- // 3 ) Both limits are constant
949
+ // 2 ) Both limits are constants
948
950
if (l1.IsConstant () && l2.IsConstant ())
949
951
{
950
952
// isLower: whatever is higher is better.
951
953
// !isLower: whatever is lower is better.
952
954
return isLower ? (l1.cns > l2.cns ? l1 : l2) : (l1.cns < l2.cns ? l1 : l2);
953
955
}
954
956
955
- // 4 ) Both limits are of the form "len + cns"
957
+ // 3 ) Both limits are BinOpArray (which is "arrLen + cns")
956
958
if (l1.IsBinOpArray () && l2.IsBinOpArray ())
957
959
{
958
- // First, if one of them is preferredBound and the other is not, use the preferredBound.
960
+ // If one of them is preferredBound and the other is not, use the preferredBound.
959
961
if (preferredBound != ValueNumStore::NoVN)
960
962
{
961
963
if ((l1.vn == preferredBound) && (l2.vn != preferredBound))
@@ -969,22 +971,23 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
969
971
}
970
972
971
973
// Otherwise, just use the one with the higher/lower constant.
972
- // even if they use different arrLen - what else can we do?
974
+ // even if they use different arrLen.
973
975
return isLower ? (l1.cns > l2.cns ? l1 : l2) : (l1.cns < l2.cns ? l1 : l2);
974
976
}
975
977
976
- // 5 ) One limit is constant and the other is of the form "len + cns"
978
+ // 4 ) One of the limits is a constant and the other is BinOpArray
977
979
if ((l1.IsConstant () && l2.IsBinOpArray ()) || (l2.IsConstant () && l1.IsBinOpArray ()))
978
980
{
979
- // swap them so that l1 is BinOpArray and l2 is constant.
981
+ // l1 - BinOpArray, l2 - constant
980
982
if (l1.IsConstant ())
981
983
{
982
984
std::swap (l1, l2);
983
985
}
984
986
985
987
if (((preferredBound == ValueNumStore::NoVN) || (l1.vn != preferredBound)))
986
988
{
987
- // if we don't have a preferred bound or it doesn't match l1.vn, use l2.
989
+ // if we don't have a preferred bound,
990
+ // or it doesn't match l1.vn, use the constant (l2).
988
991
return l2;
989
992
}
990
993
@@ -994,16 +997,13 @@ void RangeCheck::MergeEdgeAssertions(Compiler* comp,
994
997
unreached ();
995
998
};
996
999
997
- if (log )
998
- {
999
- JITDUMP (" Tightening ranges [%s] and [%s] into " , range.ToString (comp), pRange->ToString (comp));
1000
- }
1001
- pRange->lLimit = tightenLimit (range.lLimit , pRange->lLimit , preferredBoundVN, true );
1002
- pRange->uLimit = tightenLimit (range.uLimit , pRange->uLimit , preferredBoundVN, false );
1003
- if (log )
1004
- {
1005
- JITDUMP (" [%s]\n " , pRange->ToString (comp));
1006
- }
1000
+ JITDUMP (" Tightening pRange: [%s] with assertedRange: [%s] into " , pRange->ToString (comp),
1001
+ assertedRange.ToString (comp));
1002
+
1003
+ pRange->lLimit = tightenLimit (assertedRange.lLimit , pRange->lLimit , preferredBoundVN, true );
1004
+ pRange->uLimit = tightenLimit (assertedRange.uLimit , pRange->uLimit , preferredBoundVN, false );
1005
+
1006
+ JITDUMP (" [%s]\n " , pRange->ToString (comp));
1007
1007
}
1008
1008
}
1009
1009
0 commit comments