Currently the llvm-reduce basic-blocks pass has the habit of replacing branches with ret instructions if the sole branch target of a block has been removed. Replacing a br with a ret results in a radically different CFG that might very well fail to reproduce what we are currently trying to reduce, especially if it is loop dependent. As a result going down these paths is seldom fruitful and we are left with block sequences like the following in the final reduction
cont5830: ; preds = %for.body5828 br label %for.cond5831 for.cond5831: ; preds = %cont5830 br label %cont5833 cont5833: ; preds = %for.cond5831 br label %for.end6075 for.end6075: ; preds = %cont5833 br label %cont6078 cont6078: ; preds = %for.end6075 br label %cont6080 cont6080: ; preds = %cont6078 br label %for.cond5821
This patch instead tries to update the branch to target the next block in sequence that is not to be removed thus increasing the likelihood of still maintaining a loop (while getting rid of some useless sequential flow). Probably we should go further than this and use loop analysis to make sure not to break loop structures but until then this small change seems like a step in the right direction.