Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4788,14 +4788,11 @@ void Compiler::optHoistLoopBlocks(FlowGraphNaturalLoop* loop,
//
if (m_canHoistSideEffects)
{
// Is the value of the whole tree loop invariant?
if (!treeIsInvariant)
if (!treeIsHoistable)
{
// We have a tree that is not loop invariant and we thus cannot hoist
assert(treeIsHoistable == false);

// Check if we should clear m_canHoistSideEffects.
// If 'tree' can throw an exception then we need to set m_canHoistSideEffects to false.
// If 'tree' cannot be hoisted and can throw an exception then we need to set
// m_canHoistSideEffects to false.
// Note that calls are handled below
if (tree->OperMayThrow(m_compiler) && !tree->IsCall())
{
Expand Down Expand Up @@ -4831,11 +4828,8 @@ void Compiler::optHoistLoopBlocks(FlowGraphNaturalLoop* loop,
}

// Additional check for helper calls that throw exceptions
if (!treeIsInvariant)
if (!treeIsHoistable)
{
// We have a tree that is not loop invariant and we thus cannot hoist
assert(treeIsHoistable == false);

// Does this helper call throw?
if (!s_helperCallProperties.NoThrow(helpFunc))
{
Expand Down
28 changes: 28 additions & 0 deletions src/tests/JIT/Regression/JitBlue/GitHub_7147/GitHub_7147.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ static bool call(int x, int y)
return x == y;
}

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
static int boundsCheck(int[] array, int index, int dividend, int divisor, int count)
{
int result = 0;

for (int i = 0; i < count; i++)
{
result += array[index];
result += dividend / divisor;
}

return result;
}

[Fact]
public static int TestEntryPoint()
{
Expand Down Expand Up @@ -112,6 +126,20 @@ public static int TestEntryPoint()
// This is the expected exception
}

try
{
boundsCheck(new int[1], 5, 1, 0, 5);
errors |= 8;
}
catch (IndexOutOfRangeException)
{
// This is the expected exception
}
catch
{
errors |= 8;
}

return 100 + errors;
}
}
Expand Down
Loading