Allow a slightly wider class of constants to be inlined #38732
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently we only inline constants (i.e. replace Const() yielding
statements by the constants themselves) if the constant in question
is isbits. We do this to avoid blowing up the size of the IR by
inlining constants that are too large. However, there are some
useful small constants that this definition ignores. E.g. I
was working with structs of the form:
and the IR was littered with various pure statements that the
optimizer wouldn't inline because this struct isn't considered
isbits (side-note, I want to change that, but that's a separate
issue). Here I'm proposing changing the criteria for a struct
to be eligible for inlining slightly: Rather than just looking
for isbits, we recurse through any immutable, isbits fields and
as long as the size of all structs combined isn't too large, we
allow the inlining.