The PeepholeOptimizer misses some rewrite opportunities since it can't look through PHI instructions.
This patch implements looking through PHIs while trying to rewrite Uncoalescable copies.
It depends on the refactoring posted in: http://reviews.llvm.org/D11195
Changes include:
- Improve the ValueTracker in the PeepholeOptimizer to look through PHI instructions.
- Teach findNextSource to lookup into multiple sources returned by the ValueTracker and generate a rewrite map for clients to consume.
- Although all support is there, don't enable this for coalescable copies until we get the motivating testcases.
- Limit the length of nested PHI chains to lookup to avoid potential compile time issues. This can further improved in the presence of compelling testcases.
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.
A x86 MMX 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
I believe “nested PHIs” shouldn't appear in this sentence :).