[x86] generalize reassociation optimization in machine combiner to 2 instructions
authorSanjay Patel <spatel@rotateright.com>
Tue, 23 Jun 2015 00:39:40 +0000 (00:39 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 23 Jun 2015 00:39:40 +0000 (00:39 +0000)
commit8bd59f505ab88f16cc13427d8affb3e379511d40
tree90ba1cf7446785103e99ad32c8e2bae8259f101d
parentb06f3b4a33ff68efef7f14f1f102c54def786f8f
[x86] generalize reassociation optimization in machine combiner to 2 instructions

Currently ( D10321, http://reviews.llvm.org/rL239486 ), we can use the machine combiner pass
to reassociate the following sequence to reduce the critical path:

A = ? op ?
B = A op X
C = B op Y
-->
A = ? op ?
B = X op Y
C = A op B

'op' is currently limited to x86 AVX scalar FP adds (with fast-math on), but in theory, it could
be any associative math/logic op (see TODO in code comment).

This patch generalizes the pattern match to ignore the instruction that defines 'A'. So instead of
a sequence of 3 adds, we now only need to find 2 dependent adds and decide if it's worth
reassociating them.

This generalization has a compile-time cost because we can now match more instruction sequences
and we rely more heavily on the machine combiner to discard sequences where reassociation doesn't
improve the critical path.

For example, in the new test case:

A = M div N
B = A add X
C = B add Y

We'll match 2 reassociation patterns, but this transform doesn't reduce the critical path:

A = M div N
B = A add Y
C = B add X

We need the combiner to reject that pattern but select this:

A = M div N
B = X add Y
C = B add A

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240361 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/MachineCombiner.cpp
lib/Target/X86/X86InstrInfo.cpp
test/CodeGen/X86/fp-fast.ll
test/CodeGen/X86/machine-combiner.ll [new file with mode: 0644]