Subzero: Add branch optimization.

1. Unconditional branch to the next basic block is removed.

2. For a conditional branch with a "false" edge to the next basic block, remove the unconditional branch to the fallthrough block.

3. For a conditional branch with a "true" edge to the next basic block, invert the condition and do like #2.

This is enabled only for O2, particularly because inverting the branch condition is a marginally risky operation.

This decreases the instruction count by about 5-6%.

Also, --stats prints a final tally to make it easier to post-process the output.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/580903005
diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp
index 4de2f57..57aba6b 100644
--- a/src/IceCfgNode.cpp
+++ b/src/IceCfgNode.cpp
@@ -457,6 +457,19 @@
   }
 }
 
+void CfgNode::doBranchOpt(const CfgNode *NextNode) {
+  TargetLowering *Target = Func->getTarget();
+  // Check every instruction for a branch optimization opportunity.
+  // It may be more efficient to iterate in reverse and stop after the
+  // first opportunity, unless there is some target lowering where we
+  // have the possibility of multiple such optimizations per block
+  // (currently not the case for x86 lowering).
+  for (InstList::const_iterator I = Insts.begin(), E = Insts.end(); I != E;
+       ++I) {
+    Target->doBranchOpt(*I, NextNode);
+  }
+}
+
 // ======================== Dump routines ======================== //
 
 void CfgNode::emit(Cfg *Func) const {