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/IceTargetLowering.h b/src/IceTargetLowering.h
index b15c4f1..7383fff 100644
--- a/src/IceTargetLowering.h
+++ b/src/IceTargetLowering.h
@@ -125,6 +125,11 @@
void doNopInsertion();
// Lowers a single instruction.
void lower();
+ // Tries to do branch optimization on a single instruction. Returns
+ // true if some optimization was done.
+ virtual bool doBranchOpt(Inst * /*I*/, const CfgNode * /*NextNode*/) {
+ return false;
+ }
// Returns a variable pre-colored to the specified physical
// register. This is generally used to get very direct access to