Skip to content

llvm-reduce: Add new pass to inline call sites #134223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: users/arsenm/inline-function/split-legality-predicate-and-impl
Choose a base branch
from

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Apr 3, 2025

Added a primitive heuristic to avoid blowing up the code size
which could use more thought.

This helps cleanup some basic examples I've been looking at where
there is a worse result when just running a bug through the full
optimization pipeline vs. running just a single pass at the point
of failure.

Copy link
Contributor Author

arsenm commented Apr 3, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm arsenm added the llvm-reduce label Apr 3, 2025 — with Graphite App
@arsenm arsenm marked this pull request as ready for review April 3, 2025 09:43
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm somewhat skeptical that this really fits into llvm-reduce. Unless we make the heuristic so narrow that it's likely useless in most cases, we'll hit cases where inlining will increase the size of the reduction.

The proper way to do a reduction that involves inlining is to use reduce_pipeline.py to cut down the full optimization pipeline to a sub-pipeline on a new input. Unfortunately, this is a separate tool from llvm-reduce, and architecturally, it doesn't always quite do what we really want (which may involve running the full CGSCC pipeline for some functions but not others, rather than running a subset of the pipeline for all functions).

Pipeline reduction is something that bugpoint used to be able to do, but kind of became a second class citizen in the llvm-reduce world -- I think that's the real problem we need to address in this context.

@arsenm
Copy link
Contributor Author

arsenm commented Apr 3, 2025

I'm somewhat skeptical that this really fits into llvm-reduce. Unless we make the heuristic so narrow that it's likely useless in most cases, we'll hit cases where inlining will reduce the size of the reduction.

Most of the time I'd prefer increased IR size for reduced codegen complexity, which is what you get with inlining.

The main driver is still checking the net result with getComplexityScore (although I'm not sure how well that really works, it seems to be trying to check every possible reduced field but misses many of them). On the examples I've tried so far, it's basically produced the same result as running a single pass in the interestingness test (it just takes longer to run). More than a few times I've gotten complaints (or seen crappy reduction output in tests added to patches) from reducing running the whole pipeline in the interestingness script. The goal is to get a better result in the case where someone didn't know to get to the minimal pipeline reproducer.

Plus the pipeline reduction isn't going to artificially inline at an arbitrary point; it's still bound by optimizing profitability logic.

@regehr
Copy link
Contributor

regehr commented Apr 3, 2025

in C-Reduce we had an inliner. it (and other transformations) routinely increased the code size, but in general these were worthwhile since the eventual reduced test ended up smaller than it otherwise would have.

there's still a legitimate policy question here, which is whether people running reducers want things like inlining to be performed, or whether they're just purely looking to get the irrelevant junk stripped out of test cases. I went with the former thing and generally was happy with the outcomes. ymmv...

@regehr
Copy link
Contributor

regehr commented Apr 3, 2025

so anyway, as a reasonably heavy llvm-reduce user, I'd be happy to see this merged, but I don't have strong feelings if this ends up being the wrong thing here.

@arsenm arsenm force-pushed the users/arsenm/inline-function/split-legality-predicate-and-impl branch from 717cc01 to 61ae6ef Compare April 3, 2025 16:54
@arsenm arsenm force-pushed the users/arsenm/llvm-reduce/introduce-reduce-inline-call-sites-delta-pass branch from b70ec08 to 77d879f Compare April 3, 2025 16:54
@nickdesaulniers
Copy link
Member

I used creduce, cvise, and llvm-reduce a lot; I think inlining was the way to go.


// TODO: Should we delete the function body?
InlineFunctionInfo IFI;
if (CanInlineCallSite(*CB, IFI).isSuccess() &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you also filter with isInlineViable or no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that mostly filters cases that are incorrect to inline but we don't care about that

Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps a heuristic of reducing the total number of inlinable calls, i.e. the function being inlined cannot have any inlinable calls, would be good for not letting this run too much

Added a primitive heuristic to avoid blowing up the code size
which could use more thought.

This helps cleanup some basic examples I've been looking at where
there is a worse result when just running a bug through the full
optimization pipeline vs. running just a single pass at the point
of failure.
@arsenm arsenm force-pushed the users/arsenm/llvm-reduce/introduce-reduce-inline-call-sites-delta-pass branch from 77d879f to afa51f6 Compare May 2, 2025 19:13
@arsenm arsenm force-pushed the users/arsenm/inline-function/split-legality-predicate-and-impl branch from 61ae6ef to b3f6884 Compare May 2, 2025 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants