Generate correctly structured do-while loops.

The loop test is always emitted before the loop body.

For do-while loops, use a phi node to track whether we're
on the first loop iteration, and only check the loop test
on the second and subsequent iterations.

For do-while loops, the loop test branch no longer occurs
at the top of the loop, so it must get its own selection
merge instruction.

A block can't be the target of more than one merge instruction.
So when the loop test executes after the body (as in do-while in GLSL)
we need to introduce a dummy block to be the target of the selection
merge just before the loop test conditional branch.

The other arm of the branch exits the loop and hence is the
"break block" exception in the structured control flow rules.
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index 7f9214c..dac5958 100644
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -1147,28 +1147,18 @@
     // body emission needs to know what the for-loop terminal is when it sees a "continue"
     loopTerminal.push(node->getTerminal());
 
-    builder.makeNewLoop();
-
-    bool bodyOut = false;
-    if (! node->testFirst()) {
-        builder.endLoopHeaderWithoutTest();
-        if (node->getBody()) {
-            breakForLoop.push(true);
-            node->getBody()->traverse(this);
-            breakForLoop.pop();
-        }
-        bodyOut = true;
-        builder.createBranchToLoopTest();
-    }
+    builder.makeNewLoop(node->testFirst());
 
     if (node->getTest()) {
         node->getTest()->traverse(this);
         // the AST only contained the test computation, not the branch, we have to add it
         spv::Id condition = builder.accessChainLoad(TranslatePrecisionDecoration(node->getTest()->getType()));
         builder.createLoopTestBranch(condition);
+    } else {
+        builder.createBranchToBody();
     }
 
-    if (! bodyOut && node->getBody()) {
+    if (node->getBody()) {
         breakForLoop.push(true);
         node->getBody()->traverse(this);
         breakForLoop.pop();