Page MenuHomePhabricator

[PowerPC] Look through copies for compare elimination
ClosedPublic

Authored by nemanjai on Mar 21 2019, 3:08 AM.

Details

Summary

We currently miss the opportunities for optmizing comparisons in the peephole optimizer if the input is the result of a COPY since we look for record-form versions of the producing instruction.

This patch simply lets the optimization peek through copies.

Diff Detail

Repository
rL LLVM

Event Timeline

nemanjai created this revision.Mar 21 2019, 3:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2019, 3:08 AM
jsji requested changes to this revision.EditedMar 28 2019, 2:02 PM

Might miss some opportunity related to parameters instead. Please have a look. Thanks.

lib/Target/PowerPC/PPCInstrInfo.cpp
1669 ↗(On Diff #191650)

This will have some problem with parameter/return COPY: We will get HW reg instead, wrong MI, then mess up the search scope in line 1802 later.
See test/CodeGen/PowerPC/optcmp.ll for an example.

This revision now requires changes to proceed.Mar 28 2019, 2:02 PM
nemanjai updated this revision to Diff 192771.Mar 28 2019, 8:05 PM

Updated to not look through copies if that leads to a physical register since that will never produce a defining MI.

Might miss some opportunity related to parameters instead. Please have a look. Thanks.

Thank you so much for catching this. This was just a dumb oversight on my part. I originally had something along these lines and changed it because getUniqueVRegDef() won't assert on physical registers. However, I unfortunately changed it after I ran my usual bootstrap tests with lit and test-suite and just prior to posting.

jsji accepted this revision.Mar 29 2019, 7:20 AM

LGTM.

This revision is now accepted and ready to land.Mar 29 2019, 7:20 AM
stefanp accepted this revision.Mar 29 2019, 10:39 AM

Have a couple of minor nits about the test case but that is all.
LGTM.

test/CodeGen/PowerPC/eliminate-compare-of-copy.ll
7 ↗(On Diff #192771)

I usually add a CHECK: blr at the end so that I know where the end of the function is. In a way it is just like adding the CHECK-LABEL at the start.

14 ↗(On Diff #192771)

nit:
Cleanup: I don't think that you need the #0, #1 or #2.

nemanjai marked 4 inline comments as done.May 2 2019, 4:44 AM
nemanjai added inline comments.
test/CodeGen/PowerPC/eliminate-compare-of-copy.ll
7 ↗(On Diff #192771)

Will add on the commit. Thanks.

14 ↗(On Diff #192771)

Fair enough, I'll remove them.

amyk accepted this revision.May 2 2019, 1:33 PM
amyk added a subscriber: amyk.

This looks good to me.

This revision was automatically updated to reflect the committed changes.
nemanjai marked 2 inline comments as done.