This is an archive of the discontinued LLVM Phabricator instance.

[FuncSpec] Consider constant struct arguments when specializing.
ClosedPublic

Authored by labrinea on Mar 6 2023, 6:21 AM.

Details

Summary

Optionally enabled just like integer and floating point arguments.

Diff Detail

Event Timeline

labrinea created this revision.Mar 6 2023, 6:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 6 2023, 6:21 AM
labrinea requested review of this revision.Mar 6 2023, 6:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 6 2023, 6:21 AM
ChuanqiXu added inline comments.Mar 12 2023, 7:38 PM
llvm/lib/Transforms/Utils/SCCPSolver.cpp
880–881

This looks not the same with the original statements. For example, we won't do anything if V is the OldArg and ValueState doesn't contain the OldArg.

labrinea added inline comments.Mar 13 2023, 10:04 AM
llvm/lib/Transforms/Utils/SCCPSolver.cpp
880–881

Looking at what handleCallArguments() does, makes me think that OldArg ought to be in either ValueState or StructValueState. That said I am wondering whether it's better to just call Solver.visit(CallSite) for the callsites of specializations right after we've updated them. This would essentially make markArgInFuncSpecialization() obsolete. Lemme try this and run a few tests.

ChuanqiXu added inline comments.Mar 14 2023, 1:50 AM
llvm/lib/Transforms/Utils/SCCPSolver.cpp
880–881

Agreed. It looks cleaner at least.

labrinea added inline comments.Mar 15 2023, 11:18 AM
llvm/lib/Transforms/Utils/SCCPSolver.cpp
880–881

I've raised D146158.

labrinea updated this revision to Diff 505771.Mar 16 2023, 4:53 AM

rebased on parent

ChuanqiXu accepted this revision.Mar 23 2023, 2:32 AM

LGTM now.

llvm/lib/Transforms/Utils/SCCPSolver.cpp
818
This revision is now accepted and ready to land.Mar 23 2023, 2:32 AM
labrinea updated this revision to Diff 512885.EditedApr 12 2023, 10:40 AM

This is basically the same revision as https://reviews.llvm.org/D145374?id=502612, where markArgInFuncSpecialization was adapted to support struct arguments. As @chill pointed out in D147132, the deprecated function has the potential to be more efficient if funcspec-for-literal-constant gets enabled by default, so I am putting it back in. To answer @ChuanqiXu's comment: arguments we are not specializing on, must be present either in ValueStateor StructValueState therefore the specialization can inherit their lattice value from the original function. The existing code does not handle structs, hence the check I suppose? (a struct won't be present in the standard value map)

chill added inline comments.Apr 13 2023, 10:12 AM
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
668–673

Maybe delete this part?

labrinea updated this revision to Diff 513561.Apr 14 2023, 6:22 AM

Changes from last revision:

  • Renamed markArgInFuncSpecialization to handleSpecializationArguments as a better description.
  • Rewrote the above function such that:
    • the lattice state of non constant arguments is copied from the original function without recomputing
    • the arguments are not pushed to the solver's worklists (there's no need for it)
    • Function::arg_iterator is used rather than Argument * directly
  • Inlined isValidArgumentType and removed repeated check for int/float types
labrinea requested review of this revision.Apr 14 2023, 6:22 AM
labrinea added inline comments.Apr 14 2023, 6:28 AM
llvm/lib/Transforms/Utils/SCCPSolver.cpp
876

I'll replace this with ValueLatticeElement

chill added a comment.Apr 17 2023, 9:43 AM

LGTM too, cheers!

llvm/lib/Transforms/Utils/SCCPSolver.cpp
843

handleXXX is very uninformative, it might be good in a contexts where we don't know
what kind of "handling" is done by the caller (like e.g. "visit"), but in this specific case
of setitng up/initialising lattice values for the parameters it's better called just like that, something like
initSpecializationParemetersLaticeValues, setupSpecArgsValueStates, etc.

chill accepted this revision.Apr 17 2023, 9:44 AM
This revision is now accepted and ready to land.Apr 17 2023, 9:44 AM
labrinea added inline comments.Apr 17 2023, 10:02 AM
llvm/lib/Transforms/Utils/SCCPSolver.cpp
843

Agree thanks. I was thinking of SetLatticeValueForSpecializationArguments but it was a bit long. We already have similar names: getLatticeValueFor, removeLatticeValueFor and resetLatticeValueFor (see D146158).

This revision was landed with ongoing or failed builds.Apr 17 2023, 10:40 AM
This revision was automatically updated to reflect the committed changes.