SimplifyCFG scans common instructions in two basic blocks after conditional branch and hoist them before the branch.
The current implementation finds common instructions if the common instruction sequence starts from the top of the BBs without other instructions.
This patch allows other instructions to be placed before the common instruction sequence by scanning more instructions in BBs. To avoid excessive cost, the scan is limited to up to 10 instructions from the top of the BB.
This additional hoisting gives code size reduction and also may result in further CFG optimizations, e.g. using a select instruction instead of the branch.
With this patch, about 67k more instructions are hoisted while bootstrap test (it is about 1.5x increase). The limit of the scan range (10 instructions) covers about 95% of the opportunity. The changes in the build time of the bootstrap test was almost negligible.
The way you're counting instructions here is wrong: you have to skip debug info.
It looks like this can only hoist one instruction each time HoistThenElseCodeToIf is called?