Skip to content

Commit 87959c6

Browse files
authored
Don't run RangeCheck if no GT_BOUNDS_CHECK were seen (#112512)
1 parent eb99e93 commit 87959c6

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

src/coreclr/jit/compiler.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7578,6 +7578,7 @@ class Compiler
75787578
#define OMF_HAS_RECURSIVE_TAILCALL 0x00040000 // Method contains recursive tail call
75797579
#define OMF_HAS_EXPANDABLE_CAST 0x00080000 // Method contains casts eligible for late expansion
75807580
#define OMF_HAS_STACK_ARRAY 0x00100000 // Method contains stack allocated arrays
7581+
#define OMF_HAS_BOUNDS_CHECKS 0x00200000 // Method contains bounds checks
75817582

75827583
// clang-format on
75837584

@@ -7618,6 +7619,16 @@ class Compiler
76187619
optMethodFlags |= OMF_HAS_STATIC_INIT;
76197620
}
76207621

7622+
bool doesMethodHaveBoundsChecks()
7623+
{
7624+
return (optMethodFlags & OMF_HAS_BOUNDS_CHECKS) != 0;
7625+
}
7626+
7627+
void setMethodHasBoundsChecks()
7628+
{
7629+
optMethodFlags |= OMF_HAS_BOUNDS_CHECKS;
7630+
}
7631+
76217632
bool doesMethodHaveExpandableCasts()
76227633
{
76237634
return (optMethodFlags & OMF_HAS_EXPANDABLE_CAST) != 0;

src/coreclr/jit/morph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8693,7 +8693,7 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA
86938693
break;
86948694

86958695
case GT_BOUNDS_CHECK:
8696-
8696+
setMethodHasBoundsChecks();
86978697
fgAddCodeRef(compCurBB, tree->AsBoundsChk()->gtThrowKind);
86988698
break;
86998699

src/coreclr/jit/rangecheck.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
//
1515
PhaseStatus Compiler::rangeCheckPhase()
1616
{
17+
if (!doesMethodHaveBoundsChecks() || (fgSsaPassesCompleted == 0))
18+
{
19+
return PhaseStatus::MODIFIED_NOTHING;
20+
}
21+
1722
RangeCheck rc(this);
1823
const bool madeChanges = rc.OptimizeRangeChecks();
1924
return madeChanges ? PhaseStatus::MODIFIED_EVERYTHING : PhaseStatus::MODIFIED_NOTHING;
@@ -1711,11 +1716,6 @@ void RangeCheck::MapMethodDefs()
17111716
// Entry point to range check optimizations.
17121717
bool RangeCheck::OptimizeRangeChecks()
17131718
{
1714-
if (m_pCompiler->fgSsaPassesCompleted == 0)
1715-
{
1716-
return false;
1717-
}
1718-
17191719
bool madeChanges = false;
17201720

17211721
// Walk through trees looking for arrBndsChk node and check if it can be optimized.

src/coreclr/jit/valuenum.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15074,8 +15074,8 @@ void Compiler::vnPrint(ValueNum vn, unsigned level)
1507415074

1507515075
// Methods of ValueNumPair.
1507615076
ValueNumPair::ValueNumPair()
15077-
: m_liberal(ValueNumStore::NoVN)
15078-
, m_conservative(ValueNumStore::NoVN)
15077+
: m_conservative(ValueNumStore::NoVN)
15078+
, m_liberal(ValueNumStore::NoVN)
1507915079
{
1508015080
}
1508115081

src/coreclr/jit/valuenumtype.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ enum ValueNumKind
3434
struct ValueNumPair
3535
{
3636
private:
37-
ValueNum m_liberal;
3837
ValueNum m_conservative;
38+
ValueNum m_liberal;
3939

4040
public:
4141
ValueNum GetLiberal() const
@@ -116,8 +116,8 @@ struct ValueNumPair
116116
ValueNumPair();
117117

118118
ValueNumPair(ValueNum lib, ValueNum cons)
119-
: m_liberal(lib)
120-
, m_conservative(cons)
119+
: m_conservative(cons)
120+
, m_liberal(lib)
121121
{
122122
}
123123

0 commit comments

Comments
 (0)