[PeepholeOptimizer] Look through PHIs to find additional register sources
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Wed, 19 Aug 2015 18:53:36 +0000 (18:53 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Wed, 19 Aug 2015 18:53:36 +0000 (18:53 +0000)
commit71a40e6fef2cb4357a6bd5caabe901dacedce088
tree1a2afc7b9bec7aa9e02b5129a9d0ecbb783e49a0
parent52dfca7612550d1f21890c3db08b113c19be363e
[PeepholeOptimizer] Look through PHIs to find additional register sources

Reintroduce r245442. Remove an overly conservative assertion introduced
in r245442. We could replace the assertion to use `shareSameRegisterFile`
instead, but in that point in `insertPHI` we already lost the original
Def subreg to check against. So drop the assertion completely.

Original commit message:

- Teaches the ValueTracker in the PeepholeOptimizer to look through PHI
instructions.
- Add findNextSourceAndRewritePHI method to lookup into multiple sources
returnted by the ValueTracker and rewrite PHIs with new sources.

With these changes we can find more register sources and rewrite more
copies to allow coaslescing of bitcast instructions. Hence, we eliminate
unnecessary VR64 <-> GR64 copies in x86, but it could be extended to
other archs by marking "isBitcast" on target specific instructions. The
x86 example follows:

A:
  psllq %mm1, %mm0
  movd  %mm0, %r9
  jmp C

B:
  por %mm1, %mm0
  movd  %mm0, %r9
  jmp C

C:
  movd  %r9, %mm0
  pshufw  $238, %mm0, %mm0

Becomes:

A:
  psllq %mm1, %mm0
  jmp C

B:
  por %mm1, %mm0
  jmp C

C:
  pshufw  $238, %mm0, %mm0

Differential Revision: http://reviews.llvm.org/D11197
rdar://problem/20404526

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245479 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Target/TargetInstrInfo.h
lib/CodeGen/PeepholeOptimizer.cpp
lib/Target/X86/X86InstrMMX.td
test/CodeGen/X86/mmx-coalescing.ll [new file with mode: 0644]