Skip to content

Commit

Permalink
Recognize mod-free helper calls in loop hoisting
Browse files Browse the repository at this point in the history
Update the code in `optHoistLoopExprsForTree` that identifies exprs with
memory side-effects to recognize helper calls that don't mutate the heap;
this allows hoisting invariant exprs past such helper calls.

Fixes #6901.
  • Loading branch information
JosephTremoulet committed Sep 1, 2016
1 parent daf6c2c commit a15ce32
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6226,9 +6226,28 @@ bool Compiler::optHoistLoopExprsForTree(
// be hoisted so that they are evaluated in the same order as they would have been in the loop,
// and therefore throw exceptions in the same order. (So we don't use GTF_GLOBALLY_VISIBLE_SIDE_EFFECTS
// here, since that includes exceptions.)
if (tree->gtFlags & GTF_CALL)
if (tree->IsCall())
{
*pFirstBlockAndBeforeSideEffect = false;
// If it's a call, it must be a helper call, and be not mutate the heap.
// Further, if it may run a cctor, it must be labeled as "Hoistable"
// (meaning it won't run a cctor because the class is not precise-init).
GenTreeCall* call = tree->AsCall();
if (call->gtCallType != CT_HELPER)
{
*pFirstBlockAndBeforeSideEffect = false;
}
else
{
CorInfoHelpFunc helpFunc = eeGetHelperNum(call->gtCallMethHnd);
if (s_helperCallProperties.MutatesHeap(helpFunc))
{
*pFirstBlockAndBeforeSideEffect = false;
}
else if (s_helperCallProperties.MayRunCctor(helpFunc) && (call->gtFlags & GTF_CALL_HOISTABLE) == 0)
{
*pFirstBlockAndBeforeSideEffect = false;
}
}
}
else if (tree->OperIsAssignment())
{
Expand Down

0 comments on commit a15ce32

Please sign in to comment.