Do loop cloning only if zero trip test can be ensured.
authorRuss Keldorph <Russ.Keldorph@microsoft.com>
Tue, 12 Jan 2016 00:51:49 +0000 (16:51 -0800)
committerRuss Keldorph <Russ.Keldorph@microsoft.com>
Tue, 12 Jan 2016 23:25:08 +0000 (15:25 -0800)
commit8657824294d106720cef63d872beeca7bc277e1b
tree1f91edb12486e59faefa38b31f096b93c51be1bd
parentfb9eda843f9fc89656a9782ea46c0df8ec4d75e3
Do loop cloning only if zero trip test can be ensured.

The problem is our loop detection logic detects the loop structure, but it
doesnt know the code outside the loop structure, esp., nothing about the
edge from the "head" into the loop "entry" block.

In the bug case, there is no zero-trip test in the "head", so the entrance
into the loop is not guarded. Note that the other point of entrance into
the "entry" block is from the "top" block which will be guarded by the
loop "bottom" test.

One way to make sure is when we invert a while loop into a do-while with
an explicit compiler cloned zero trip test, in fgOptWhileLoop, i.e., we
mark it as good to optimize with a flag. The fix marks the loop as ZTT.

The caveat is the JIT doesnt always do loop inversion.

This change is more conservative than it needs to be in the interest of
managing risk.
src/jit/gentree.h
src/jit/optimizer.cpp
tests/src/JIT/RyuJIT/DoWhileBndChk.cs [new file with mode: 0644]
tests/src/JIT/RyuJIT/DoWhileBndChk.csproj [new file with mode: 0644]
tests/src/JIT/RyuJIT/app.config [new file with mode: 0644]