This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Add an MI SSA peephole pass.
ClosedPublic

Authored by wschmidt on Oct 26 2015, 9:32 AM.

Details

Summary

This patch adds a pass for doing PowerPC peephole optimizations at the MI level while the code is still in SSA form. This allows for easy modifications to the instructions while depending on a subsequent pass of DCE. Both passes are very fast due to the characteristics of SSA.

At this time, the only peepholes added are for cleaning up various redundancies involving the XXPERMDI instruction. However, I would expect this will be a useful place to add more peepholes for
inefficiencies generated during instruction selection. The pass is placed after VSX swap optimization, as it is best to let that pass remove unnecessary swaps before performing any remaining clean-ups.

The utility of these clean-ups are demonstrated by changes to four existing test cases, all of which now have tighter expected code generation. I've also added Eric Schweiz's bugpoint-reduced test from PR25157, for which we now generate tight code. One other test started failing for me, and I've fixed it
(test/Transforms/PlaceSafepoints/finite-loops.ll) as well; this is not related to my changes, and I'm not sure why it works before and not after. The problem is that the CHECK-NOT: of "statepoint" from test1 fails because of the "statepoint" in test2, and so forth. Adding a CHECK-LABEL in between keeps the different occurrences of that string properly scoped.

Diff Detail

Repository
rL LLVM

Event Timeline

wschmidt updated this revision to Diff 38426.Oct 26 2015, 9:32 AM
wschmidt retitled this revision from to [PowerPC] Add an MI SSA peephole pass..
wschmidt updated this object.
wschmidt added reviewers: hfinkel, kbarton, nemanjai.
wschmidt set the repository for this revision to rL LLVM.
wschmidt added a subscriber: llvm-commits.
hfinkel added inline comments.Oct 27 2015, 12:01 PM
lib/Target/PowerPC/PPCMIPeephole.cpp
72

You should use:

TII = MF.getSubtarget<PPCSubtarget>().getInstrInfo();

just like we have in PPCTLSDynamicCall.cpp (looks like you should fix this in PPCVSXSwapRemoval.cpp too).

97

Add space before (.

134

This seems somewhat misleading. I think it should say:

"Optimizing splat/swap or splat/splat to splat/copy:

because you're not actually eliminating the splat.

178

You need to make sure that the MI you want to erase does not have other users before you erase it.

209

We should not use unbounded recursion without a good reason, and making this into a loop seems straightforward. Please make this loop instead.

Sorry it took me a while to get back to this. I'll make all suggested fixes except for the ToErase one, as noted.

lib/Target/PowerPC/PPCMIPeephole.cpp
178

That's not necessary here because I'm replacing the ToErase instruction with a different instruction that defines the same virtual register.

209

Good point. Will do.

wschmidt updated this revision to Diff 38985.Nov 2 2015, 2:28 PM

Updated to address Hal's comments. Thanks, Hal!

When I patched up to a week later, a couple of more test cases had landed that now have better code generation with my patch. Those changes are included here as well.

kbarton edited edge metadata.Nov 9 2015, 9:20 AM

Only one minor comment - do we care about collecting any statistics for this?
It seems that it might be useful to know whether this is doing anything, at least for debugging.

Aside from that, LGTM.

hfinkel accepted this revision.Nov 10 2015, 5:08 AM
hfinkel edited edge metadata.

Only one minor comment - do we care about collecting any statistics for this?
It seems that it might be useful to know whether this is doing anything, at least for debugging.

Aside from that, LGTM.

LGTM too.

This revision is now accepted and ready to land.Nov 10 2015, 5:08 AM
wschmidt closed this revision.Nov 10 2015, 1:41 PM

r252651, thanks!