Subzero: Don't contract an empty node that branches to itself. BUG= https://code.google.com/p/nativeclient/issues/detail?id=4307 R=ascull@google.com Review URL: https://codereview.chromium.org/1337113008 .
diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp index d57224b..58e74d4 100644 --- a/src/IceCfgNode.cpp +++ b/src/IceCfgNode.cpp
@@ -748,8 +748,12 @@ else if (!I.isRedundantAssign()) return; } - Branch->setDeleted(); assert(OutEdges.size() == 1); + // Don't try to delete a self-loop. + if (OutEdges[0] == this) + return; + + Branch->setDeleted(); CfgNode *Successor = OutEdges.front(); // Repoint all this node's in-edges to this node's successor, unless // this node's successor is actually itself (in which case the
diff --git a/tests_lit/llvm2ice_tests/contract.ll b/tests_lit/llvm2ice_tests/contract.ll new file mode 100644 index 0000000..59e6491 --- /dev/null +++ b/tests_lit/llvm2ice_tests/contract.ll
@@ -0,0 +1,18 @@ +; This tests that an empty node pointing to itself is not contracted. +; https://code.google.com/p/nativeclient/issues/detail?id=4307 +; +; RUN: %p2i -i %s --filetype=obj --disassemble --args -O2 \ +; RUN: | FileCheck %s + +define void @SimpleBranch() { +label0: + br label %label2 +label1: + br label %label1 +label2: + br label %label1 +} + +; CHECK-LABEL: SimpleBranch +; CHECK-NEXT: jmp 0 <SimpleBranch> +; CHECK-NEXT: hlt