This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] eliminate partially redundant compare instruction
ClosedPublic

Authored by inouehrs on Sep 25 2017, 6:32 AM.

Details

Summary

This is a follow-on of D37211.

D37211 eliminates a compare instruction if two conditional branches can be made based on the one compare instruction, e.g.

if (a == 0) { ... }
else if (a < 0) { ... }

This patch extends this optimization to support partially redundant cases, which often happen in while loops.
For example, one compare instruction is moved from the loop body into the preheader by this optimization in the following example.

do {
  if (a == 0) dummy1();
  a = func(a);
} while (a > 0);

Diff Detail

Repository
rL LLVM

Event Timeline

inouehrs created this revision.Sep 25 2017, 6:32 AM
hfinkel added inline comments.Sep 26 2017, 2:27 PM
lib/Target/PowerPC/PPCMIPeephole.cpp
571 ↗(On Diff #116543)

I'm not sure how this full-copy case would come up, unless:

  1. The source or destination is a physical register (but we bail out in that case)
  2. The source or destination have different register classes
  3. This is run after PHI elimination (which this pass is not)

I can't think of a case where (2) would come up (we don't have different register classes for GPRs, except for r0 restrictions, but I believe there we just end up with one vreg with a union register class).

I short, unless you've seen this in practice, I recommend not handling it at all.

616 ↗(On Diff #116543)

Please remove the parentheses here.

640 ↗(On Diff #116543)

I'm okay with this, but we shouldn't have nothing in the braces. A comment is okay.

702 ↗(On Diff #116543)

another -> additional

918 ↗(On Diff #116543)

Space after first <<.

inouehrs updated this revision to Diff 116843.Sep 27 2017, 10:42 AM
inouehrs marked 4 inline comments as done.Sep 27 2017, 10:49 AM
inouehrs added inline comments.
lib/Target/PowerPC/PPCMIPeephole.cpp
571 ↗(On Diff #116543)

Disabling this full-copy case reduces the number of eliminated compares by about 1% during the bootstrap (23483 -> 23191), although I have not investigated which optimizer generates COPYs.

616 ↗(On Diff #116543)

I think we cannot eliminate the parentheses of lambda.

640 ↗(On Diff #116543)

I added comment to avoid empty block.

702 ↗(On Diff #116543)

Fixed.

918 ↗(On Diff #116543)

Fixed.

hfinkel accepted this revision.Sep 27 2017, 11:11 AM

LGTM

lib/Target/PowerPC/PPCMIPeephole.cpp
640 ↗(On Diff #116843)

containing compare -> containing the compare

641 ↗(On Diff #116843)

the BB we will -> the BB to which we will

571 ↗(On Diff #116543)

Okay.

616 ↗(On Diff #116543)

I think that you can just write:

return BB.succ_size() == 1;
This revision is now accepted and ready to land.Sep 27 2017, 11:11 AM
This revision was automatically updated to reflect the committed changes.
inouehrs marked 4 inline comments as done.