[InstCombiner] Expose opportunities to merge subtract and comparison.
authorQuentin Colombet <qcolombet@apple.com>
Mon, 9 Sep 2013 20:56:48 +0000 (20:56 +0000)
committerQuentin Colombet <qcolombet@apple.com>
Mon, 9 Sep 2013 20:56:48 +0000 (20:56 +0000)
commit2c6ef1c4339c2961745bc3747753e4f2d23ee7c6
treedf73fff89d0e603ab6c4937e31f4aef0ac0e0825
parent0b9ba182a7a91ad2ea7ef8486a4107c680650927
[InstCombiner] Expose opportunities to merge subtract and comparison.

Several architectures use the same instruction to perform both a comparison and
a subtract. The instruction selection framework does not allow to consider
different basic blocks to expose such fusion opportunities.

Therefore, these instructions are “merged” by CSE at MI IR level.

To increase the likelihood of CSE to apply in such situation, we reorder the
operands of the comparison, when they have the same complexity, so that they
matches the order of the most frequent subtract.
E.g.,

icmp A, B
...
sub B, A

<rdar://problem/14514580>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190352 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/icmp.ll