This is an archive of the discontinued LLVM Phabricator instance.

If conversion to conditional select for -Oz or -Os unprofitable for single operation blocks
Needs ReviewPublic

Authored by ramred01 on Apr 3 2019, 9:11 AM.

Details

Summary

When we are compiling for -Os or -Oz, performing if conversion to conditional select when the two branches of the if have exactly one instruction in them tends to generate more code.

We prevent it at three stages. The first is in early if conversion. We count the number of instructions in each block and if it is less than two we return without changes.

The next is in the tail duplicator. If there are no select or GEP instructions in the layout predecessor of the tail duplicated block, then we do not splice the tail duplicated block into the layout predecessor. This prevents generation of some unnecessary branches.

The third is in simplify CFG. If the if statement results in a two entry PHI node at the beginning of a basic block, then we try to fold it into a SELECT. In case the incoming edges to the PHI node are from basic blocks having exactly one instruction, we prevent the generation of this SELECT.

Diff Detail

Event Timeline

ramred01 created this revision.Apr 3 2019, 9:11 AM
vsk added subscribers: ab, t.p.northover, vsk.EditedApr 3 2019, 10:51 AM

Thanks for working on this. I’d suggest splitting this into a sequence of three patches (with tests and accompanying code size numbers), so its effects can be understood better.