This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Follow-up to r318436 to get the missed CSE opportunities
ClosedPublic

Authored by nemanjai on Nov 22 2017, 5:03 AM.

Details

Summary

In r318436, the PPC back end improved the code-gen for stores of constant values. However, there's a class of patterns that this misses and a class that it actually makes worse.

  • The revision isn't able to do anything for indexed stores (pre-inc in the case of PPC) as the target-specific DAG combine isn't run on the indexed stores produced by the generic combiner.
  • The revision makes code-gen worse for 8-32 bit stores of negative values as the new 64-bit constant isn't sign-extended so just appears to be a large positive value. Example:
extern int IVal;
void test() {
  IVal = -7;
}

Generates this code:

li 4, 0
oris 4, 4, 65535
ori 4, 4, 65529
stw 4, 0(3)

Rather than the obviously better:

li 4, -7
stw 4, 0(3)

This patch does the following:

  • Modifies the generic DAG combiner to add the new indexed LD/ST to the worklist so the target-specific combiner has an opportunity to fix it up
  • Sign-extends the constant to 64-bit from the bit width of MemoryVT
  • Canonicalizes the materialization of constants that fit in a 16-bit signed field so that the DAG can CSE them as expected (i.e. 64-bit constants are always materialized as values sign-extended to 64 bits)

The result is

  • Pre-inc loads are handled
  • Good code-gen for storing negative constants
  • CSE for all 64-bit constants that can be emitted using just the PPC "Load-immediate" instruction

Diff Detail

Repository
rL LLVM

Event Timeline

nemanjai created this revision.Nov 22 2017, 5:03 AM
bogner accepted this revision.Nov 30 2017, 1:35 PM

This change is really three different changes. In general it's easier to review changes that only do one thing. The DAGCombiner change here looks correct, and I took a cursory glance at the PPC changes and didn't see anything wrong.

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
11372 ↗(On Diff #123913)

This change LGTM.

lib/Target/PowerPC/PPCISelDAGToDAG.cpp
862–863 ↗(On Diff #123913)

This can be simplified using range-for and N->uses().

This revision is now accepted and ready to land.Nov 30 2017, 1:35 PM

This change is really three different changes. In general it's easier to review changes that only do one thing. The DAGCombiner change here looks correct, and I took a cursory glance at the PPC changes and didn't see anything wrong.

First off, thanks for the review Justin.

I agree that this kind of conflates multiple conceptual changes and am happy to split them out on the commit (or even just commit the first one now and post the other two as separate reviews).

  1. The DAGCombiner change
  2. Sign-extending the immediate for the wider constant to be stored
  3. Improvements to materialization of constants

I felt that posting the DAGCombiner change in isolation wouldn't provide enough motivation so I wrapped it into this. Sorry about that.

lib/Target/PowerPC/PPCISelDAGToDAG.cpp
862–863 ↗(On Diff #123913)

Good point. I wonder why I did this. I think the original implementation needed to increment the iterator within the loop. In any case, it is now good for a range-for. Thanks for pointing it out.

This revision was automatically updated to reflect the committed changes.