Inline: Fix single-block loop caller cases
authorDavid Neto <dneto@google.com>
Thu, 31 Aug 2017 19:47:31 +0000 (15:47 -0400)
committerDavid Neto <dneto@google.com>
Fri, 1 Sep 2017 19:47:17 +0000 (15:47 -0400)
commitefff5fabfab59185bc9177f2e294f6cf27f094a5
treeee728497362646cc7f1131d30da975579713bdc7
parentcff2cd3343bbd4cca6b0f49507deb3a2f5e4c5c9
Inline: Fix single-block loop caller cases

If the caller block is a single-block loop and inlining will
replace the caller block by several blocks, then:
- The original OpLoopMerge instruction will end up in the *last*
  such block.  That's the wrong place to put it.
- Move it back to the end of the first block.
- Update its Continue Target ID to point to the last block

We also have to take care of cases where the inlined code
begins with a structured header block.  In this case
we need to ensure the restored OpLoopMerge does not appear
in the same block as the merge instruction from the callee's
first block.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/787
source/opt/inline_pass.cpp
test/opt/inline_test.cpp