
#8275: Loopification breaks profiling
----------------------------------------+----------------------------------
Reporter: jstolarek | Owner: jstolarek
Type: bug | Status: new
Priority: highest | Milestone:
Component: Profiling | Version: 7.7
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Building GHC failed | Unknown/Multiple
Test Case: | Difficulty: Unknown
Blocking: 8298 | Blocked By:
| Related Tickets:
----------------------------------------+----------------------------------
Comment (by jstolarek):
Edward, there is some progress. There is a single test in the testsuite
that fails when loopification is turned on, but works if it is off. That
test is T1735. Assuming that you built GHC with profiling libraries you
can run this test from `testsuite/tests` with:
{{{
make WAY=normal EXTRA_HC_OPTS="-prof -fprof-auto -rtsopts" TEST=T1735
}}}
and it should pass. Including `-floopification` on the list of extra
options should make the test fail. Examining the Cmm dumps is a pain -
they are over 200k lines - but I found a single place where loopification
occurs. Attached are the dumps of this single function with and without
loopification. `-input` suffix denotes code produced by the code
generator, `-output` suffix denotes code after it has gone through all
optimisations in Cmm pipeline.
If you look at the output code you will notice one incorrect
transformation in the loopified version: stack check gets duplicated and
inserted at the end of function, right before making a tail call. There
are two issues here:
1) Correctness. Cmm pipeline performs an incorrect transformation on a
valid Cmm input program. It duplicates stack check at the end of a
function, which violates assumption that stack checks are made only at the
entry to a function (see !CmmLayoutStack, line 208). Putting stack check
at the end makes it invalid, because we set required amount of stack to be
a fixed value. As a result at the end of a function we are checking for
more stack that we actually need (becuase we have moved the stack
pointer). Simon proposes to fix that by referring to `