This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyCFG] Expanding scope for hoisting common instructions after branch
AbandonedPublic

Authored by inouehrs on Feb 21 2018, 3:34 AM.

Details

Summary

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.

Diff Detail

Event Timeline

inouehrs created this revision.Feb 21 2018, 3:34 AM

LLVM has a GVNHoist pass, which is both more efficient and more effective than anything we can do in SimplifyCFG. (It's currently off by default, but it could probably be turned on with a bit more testing/bugfixing.) I would rather focus on getting that turned on, instead of doing something like this.

lib/Transforms/Utils/SimplifyCFG.cpp
1275

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?

inouehrs abandoned this revision.Feb 21 2018, 8:57 PM

@efriedma I agree. I confirmed that GVNHoist can optimize my motivating examples. So I abandon this.
I hope GVNHoist will become default on soon. Thanks!