This is an archive of the discontinued LLVM Phabricator instance.

[PeepholeOptimizer] Look through PHIs to find additional register sources
ClosedPublic

Authored by bruno on Jul 14 2015, 1:48 PM.

Details

Summary

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

Diff Detail

Repository
rL LLVM

Event Timeline

bruno updated this revision to Diff 29707.Jul 14 2015, 1:48 PM
bruno retitled this revision from to [PeepholeOptimizer] Look through PHIs to find additional register sources.
bruno updated this object.
bruno added reviewers: qcolombet, MatzeB.
bruno set the repository for this revision to rL LLVM.
bruno added a subscriber: llvm-commits.
qcolombet accepted this revision.Jul 14 2015, 2:48 PM
qcolombet edited edge metadata.

Hi Bruno,

LGTM with one fix.

Thanks,
-Quentin

lib/CodeGen/PeepholeOptimizer.cpp
105

I believe “nested PHIs” shouldn't appear in this sentence :).

236

We should check that the number of sources is the same for both trackers as well.

Same for the Inst member.

This revision is now accepted and ready to land.Jul 14 2015, 2:48 PM
bruno added a comment.Jul 14 2015, 2:52 PM

Right, gonna fix that!

Thanks again Quentin.

bruno closed this revision.Jul 15 2015, 10:48 AM

Committed in r242295!