[CGP] transform select instructions into branches and sink expensive operands
authorSanjay Patel <spatel@rotateright.com>
Mon, 19 Oct 2015 21:59:12 +0000 (21:59 +0000)
committerSanjay Patel <spatel@rotateright.com>
Mon, 19 Oct 2015 21:59:12 +0000 (21:59 +0000)
commit3b75c0484a47712cec877ec9f2cd47c35b27093d
tree002ba5293cc5ac4cdc7d62dc50160d9ff3e84acd
parentd765f759fab6eaa9caa1765e4edddb4da511af4d
[CGP] transform select instructions into branches and sink expensive operands

This was originally checked in at r250527, but reverted at r250570 because of PR25222.
There were at least 2 problems:
1. The cost check was checking for an instruction with an exact cost of TCC_Expensive;
that should have been >=.
2. The cause of the clang stage 1 failures was illegally sinking 'call' instructions;
we can't sink instructions that may have side effects / are not safe to execute speculatively.

Fixed those conditions in sinkSelectOperand() and added test cases.

Original commit message:
This is a follow-up to the discussion in D12882.

Ideally, we would like SimplifyCFG to be able to form select instructions even when the operands
are expensive (as defined by the TTI cost model) because that may expose further optimizations.
However, we would then like a later pass like CodeGenPrepare to undo that transformation if the
target would likely benefit from not speculatively executing an expensive op (this patch).

Once we have this safety mechanism in place, we can adjust SimplifyCFG to restore its
select-formation behavior that changed with r248439.

Differential Revision: http://reviews.llvm.org/D13297

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250743 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CodeGenPrepare.cpp
test/Transforms/CodeGenPrepare/X86/select.ll [new file with mode: 0644]