This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] define target hook isReallyTriviallyReMaterializable
ClosedPublic

Authored by lei on Jun 15 2017, 4:01 PM.

Details

Summary

Trivially rematerializable instructions are instructions that has no side effects and requires no operands that are not always available. The PPC instructions ADDIStocHA and ADDItocL are trivially rematerializable because it does a ADDIS/ADDI on the TOC register and an immediate. On PowerPC the ABI reserves the TOC register (X2) in any functions that have calls or access global variables.

Define target hook isReallyTriviallyReMaterializable() to explicitly specify PowerPC instructions that are trivially rematerializable. This will allow MachineLICM pass to accurately identify PPC instructions that should always be hoisted.

Spec 2006 Results (>1 indicates improvement):

SpeedUp
SPEC_INT
400.perlbench1.000
401.bzip21.000
403.gcc0.998
429.mcf1.009
445.gobmk1.005
456.hmmer1.001
458.sjeng1.011
462.libquantum1.006
464.h264ref1.044
471.omnetpp1.001
473.astar1.000
483.xalancbmk1.005
SPEC_FP
433.milc0.999
444.namd0.987
447.dealII1.000
450.soplex0.995
453.povray0.995
470.lbm0.996
482.sphinx31.001

Diff Detail

Repository
rL LLVM

Event Timeline

lei created this revision.Jun 15 2017, 4:01 PM
lei updated this revision to Diff 102752.Jun 15 2017, 4:29 PM
lei added inline comments.Jun 16 2017, 7:53 AM
test/CodeGen/PowerPC/licm-remat.ll
29 ↗(On Diff #102752)

This should be CHECK-DAG ... will update

lei updated this revision to Diff 102835.Jun 16 2017, 8:59 AM

update test case

lei edited the summary of this revision. (Show Details)Jun 19 2017, 6:37 AM
lei edited the summary of this revision. (Show Details)Jun 19 2017, 6:29 PM
lei edited the summary of this revision. (Show Details)Jun 19 2017, 6:34 PM
echristo added inline comments.Jun 19 2017, 6:38 PM
lib/Target/PowerPC/PPCInstrInfo.cpp
295 ↗(On Diff #102835)

This needs a comment as to why each of these need to be marked as rematerializable here rather than in the .td file.

299 ↗(On Diff #102835)

I'm not sure an unreachable is the right thing here - usually this is reserved for switch cases that can't be true rather than just a return false.

lei added inline comments.Jun 19 2017, 10:11 PM
lib/Target/PowerPC/PPCInstrInfo.cpp
295 ↗(On Diff #102835)

Will add:

// The Rematerializable flag is deprecated and if it is set, isReallyTriviallyReMaterializable() method need to be called to verify the instruction is really rematable.

echristo edited edge metadata.Jun 19 2017, 10:44 PM

Can you send out a patch to make that comment on the base routine as well?

MatzeB added a subscriber: MatzeB.Jun 19 2017, 10:50 PM
MatzeB added inline comments.
lib/Target/PowerPC/PPCInstrInfo.cpp
295 ↗(On Diff #102835)

Why do you get the impression that this flag is deprecated? It's just not the only thing checked as far as I can see.

299 ↗(On Diff #102835)

This really should only be called for opcodes with the ReMaterializable flag set, so unreachable seems correct to me.

echristo added inline comments.Jun 19 2017, 10:55 PM
lib/Target/PowerPC/PPCInstrInfo.cpp
295 ↗(On Diff #102835)

Yeah. I was wondering about that. Also, that's really confusing. The routine itself could use a comment update explaining what's going on? Or at least it wasn't horribly clear to me.

299 ↗(On Diff #102835)

Ah. I missed that, OK then. Probably needs to be something like "unknown rematerializable operation" or something.

MatzeB added inline comments.Jun 19 2017, 11:00 PM
lib/Target/PowerPC/PPCInstrInfo.cpp
295 ↗(On Diff #102835)

Indeed that is one of the many things in CodeGen that are really confusing (and unnecessarily so it seems). However stating it is deprecated will only add to to the confusion unless there are concrete plans to do something about it.

And I'd certainly welcome a change that removes the MCInstrDesc bit and only uses the callback and measures that it is indeed negligible in terms of compiletime.

nemanjai added inline comments.Jun 20 2017, 12:01 AM
lib/Target/PowerPC/PPCInstrInfo.cpp
295 ↗(On Diff #102835)

I would imagine that the comment about the deprecation of the flag comes right out of include/llvm/CodeGen/MachineInstr.h:

This flag is deprecated, please don't use it anymore.  If this
flag is set, the isReallyTriviallyReMaterializable() method is called to
verify the instruction is really rematable.
lei added inline comments.Jun 20 2017, 8:40 AM
lib/Target/PowerPC/PPCInstrInfo.cpp
295 ↗(On Diff #102835)

Yes. That is where I got the impression this flag is deprecated.

lei added inline comments.Jun 20 2017, 8:53 AM
lib/Target/PowerPC/PPCInstrInfo.cpp
295 ↗(On Diff #102835)

I'll add a comment here, but a detailed description can also be found in include/llvm/Target/TargetInstrInfo.h

/// For instructions with opcodes for which the M_REMATERIALIZABLE flag is
/// set, this hook lets the target specify whether the instruction is actually
/// trivially rematerializable, taking into consideration its operands. This
/// predicate must return false if the instruction has any side effects other
/// than producing a value, or if it requres any address registers that are
/// not always available.
/// Requirements must be check as stated in isTriviallyReMaterializable() .
virtual bool isReallyTriviallyReMaterializable(const MachineInstr &MI,
                                               AliasAnalysis *AA) const {
  return false;
}
MatzeB added inline comments.Jun 20 2017, 10:25 AM
lib/Target/PowerPC/PPCInstrInfo.cpp
295 ↗(On Diff #102835)

I would imagine that the comment about the deprecation of the flag comes right out of include/llvm/CodeGen/MachineInstr.h:

Ah, I was looking at include/llvm/Target/Target.td for the definition/explanation of the instruction flags on the tablegen side (because at the point in MCInstrDesc.h where they are defined we have no further explanation). Odd that we only had the deprecation information on the convenience function in MachineInstr.

lei updated this revision to Diff 103234.Jun 20 2017, 10:36 AM

Addressed all review comments.

lei marked 3 inline comments as done.Jun 20 2017, 10:38 AM

This is fine with me. I'll let Matthias do the final ack.

MatzeB accepted this revision.Jun 20 2017, 10:53 AM

LGTM

This revision is now accepted and ready to land.Jun 20 2017, 10:53 AM
This revision was automatically updated to reflect the committed changes.