From 25b6fae1eb26645a30b3e7e254ce0b585757351c Mon Sep 17 00:00:00 2001
From: Fawzi Mohamed <fawzi.mohamed@digia.com>
Date: Tue, 4 Nov 2014 14:55:26 +0100
Subject: [PATCH] qv4: assign split edges to the correct loop group

edge splitting had a strange logic to assign the inserted statement to a loop,
which would go wrong for example for the statement just after the loop header.
I guess that was done to increase the likelihood that the goto removed from the
final instructions.
Given that we are talking about critical edges it is always possible to emit
them in a bad order, and I do not think that the old logic was really better
than simply always use the loop group of the target which is always correct.
It might be worthwhile to ensure that the block it is emitted just before the
target block, or improve the handling of empty gotos in the backend, but in this
patch we go for the simplest solution.
If one would notice worse code, either one of the provious improvements could be
done, or the old logic could be kept, changing just the if (container == 0) to
container = toBB->containingGroup();

Change-Id: I26a488e9e2cb2b692fa8187ee658fb4dd98bfa8b
Task-number: QTBUG-41766
Reviewed-by: Bernd Lamecker <bernd.lamecker@basyskom.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
---
 src/qml/compiler/qv4ssa.cpp | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/src/qml/compiler/qv4ssa.cpp b/src/qml/compiler/qv4ssa.cpp
index d67b88b718..31e3ed867e 100644
--- a/src/qml/compiler/qv4ssa.cpp
+++ b/src/qml/compiler/qv4ssa.cpp
@@ -2991,15 +2991,7 @@ void splitCriticalEdges(IR::Function *f, DominatorTree &df, StatementWorklist &w
             toBB->in[inIdx] = newBB;
             newBB->out.append(toBB);
 
-            BasicBlock *container = 0;
-            for (container = fromBB->containingGroup(); container; container = container->containingGroup()) {
-                if (container == toBB || container == toBB->containingGroup())
-                    break;
-            }
-            if (container == 0)
-                container = fromBB->containingGroup();
-
-            newBB->setContainingGroup(container);
+            newBB->setContainingGroup(toBB->containingGroup());
 
             // patch the terminator
             Stmt *terminator = fromBB->terminator();
-- 
GitLab