This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Merge register copies
Needs ReviewPublic

Authored by inouehrs on Nov 21 2017, 5:28 AM.

Details

Summary

This patch add an optimization to hoist and merge multiple register copies among BBs as illustrated below.

         BB1--------                           BB1--------
         | ..      |                           | ..      |
         |         |                           | mr Y, X |
         | bcc     |                           | bcc     |
         -----------                           -----------
         /         \                           /         \
BB---------         BB---------      BB---------          BB---------
| mr Y, X |         | mr Y, X |  =>  |(erased) |          |(erased) |
| ..      |         | ..      |      | ..      |          | ..      |
-----------         -----------      -----------          -----------

After the optimization, a BB will be erased if the BB becomes empty (i.e. only includes an unconditional branch).

Diff Detail

Event Timeline

jtony added inline comments.Nov 21 2017, 10:32 AM
lib/Target/PowerPC/PPCRegCopyElim.cpp
326

This lambda looks more like isSameRegOperation. From here we don't know they are both COPY Operation or not. It looks to me that is implied from the calling site. In that case, I would rename it to expression what it really does. Or we could change the implementation to match the current name. Either way is fine, as long as the name and what it does is consistent. And an assertion to make sure you only get COPY operation for this lambda may be necessary.

447

The format at line 441 is right, which is good, but we are missing space after &SuccMBB and before : here. Please also check all the other range based for loop format. Thanks!

test/CodeGen/PowerPC/redundant_regcopy_3.mir
10

I tried to apply this patch and run this test case, but because this patch depends on another one, which I also tried to apply first, but that has conflicts with the latest trunk after applying. So I give up applying these patches. The test case here looks weird to me. I may misunderstanding something, but the code block layout is not the same with the one in your implementation description. Basically, bar block doesn't look like the successor of entry block. Do you mean br i1 %b, label %bar, label %foo ? Or I misunderstand the test case? Can you explain a little bit here ? Thanks!

inouehrs updated this revision to Diff 123881.Nov 22 2017, 12:03 AM

updated based on comments from @jtony

inouehrs updated this revision to Diff 123882.Nov 22 2017, 12:13 AM
inouehrs marked 2 inline comments as done.

minor touchup

inouehrs added inline comments.Nov 22 2017, 12:14 AM
lib/Target/PowerPC/PPCRegCopyElim.cpp
326

I updated to use isRegCopy helper to access source and destination registers.

447

Fixed. Thanks!

test/CodeGen/PowerPC/redundant_regcopy_3.mir
10

I updated. IR and MIR were mismatch.

Can you please re-evaluate the applicability and functionality of this patch in light of related patches that recently landed. For example, does https://reviews.llvm.org/rL323991 affect this patch?

inouehrs updated this revision to Diff 133200.Feb 7 2018, 5:13 AM
  • rebased to ToT
  • included the recent update in D39536

Can you please re-evaluate the applicability and functionality of this patch in light of related patches that recently landed. For example, does https://reviews.llvm.org/rL323991 affect this patch?

COPY source forwarding (rL323991) does not affect this optimization; they seem mostly orthogonal.
The number of reg copy merge optimizations happened are mostly unchanged by enabling/disabling the COPY source forwarding (26433 with COPY source forwarding and 26173 without COPY source forwarding during the bootstrap test).