This is the alternative method based on SimplifyCFG to solve problem mentioned in https://reviews.llvm.org/D113872, i.e., consider code
loop: ... if (cond) { // update max/min values // update indexes of max/min values }
Currently simplifycfg transforms this snippet of code to
loop: select cond ... select cond ...
This is not always profitable since we have redundant computations of select's operands. Branch is not always profitable either since branch may incur high mispredict penalty. This patch uses the cost estimation by @lebedev.ri mentioned in https://reviews.llvm.org/D113872 to enhance costmodel.
clang-format: please reformat the code