Skip to content

Conversation

@marek-safar
Copy link
Contributor

No description provided.

@marek-safar marek-safar requested a review from vitek-karas April 27, 2021 12:49
@vitek-karas
Copy link
Member

@MichalStrehovsky

I remember we discussed this a lot when we added the existing limited support for methods with parameters - and there was a relatively good reason not to do better.

What is the use case for this - where do we need it?
I would not be too worried if we scoped this only to explicitly substituted methods, but allowing full constant prop across methods with arbitrary parameters feels wrong. For example, if the method has a ref parameter and mutates it - I know we're going to still call it, but still - it feels risky.

I think this needs a good reason to add and probably lot more tests.

@MichalStrehovsky
Copy link
Member

I can't come up with examples of when ref parameters specifically would be risky, but the Rewrite any arguments pushed to stack to nop to allow possible body reduction into constant result sounds concerning. Do we know the pushes are not side-effecting?

@marek-safar
Copy link
Contributor Author

What is the use case for this - where do we need it?

We cannot evaluate as much as we could even for dotnet/runtime code. For example with this change, this condition can be now removed because it calls into method which couldn't be evaluated as const returning before.

I remember we discussed this a lot when we added the existing limited support for methods with parameters - and there was a relatively good reason not to do better.

Where do you see the risk? The logic for computing the constant value abort when argument value is used I'd like to understand what could be risky here.

allowing full constant prop across methods with arbitrary parameters feels wrong. For example, if the method has a ref parameter and mutates it - I know we're going to still call it, but still - it feels risky.

That's not what this change does. It only expands support of return constant value propagation over calls with parameters.

Rewrite any arguments pushed to stack to nop to allow possible body reduction into constant result sounds concerning. Do we know the pushes are not side-effecting?

Why is it concerning? This rewrite is done only for the purpose of the return value evaluation. It does not have an effect on the final IL.

I think this needs a good reason to add and probably lot more tests.

I originally wanted but as the change is very narrow we already had test coverage for it. Could you please suggest what other tests would you like to see added?

Copy link
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

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

We should add tests for more complex parameters. Things like:

  • passing a return value of a method as a param
  • conditions in the param

And set it up such that we have to try to get "past" it - that is make this complex thing the last one pushed on the stack and make sure there's something else before it. You added code for going backwards finding all the parameter setup instructions, but the tests all use simple constants and fields only.

@vitek-karas
Copy link
Member

What is the impact of this change - how much does it help? (just curious)

@marek-safar
Copy link
Contributor Author

We should add tests for more complex parameters.

Added a few more, let me know if there is some other interesting il patter to cover

all use simple constants and fields only

There are already some tests, see e.g. https://github.com/marek-safar/linker/blob/constprop/test/Mono.Linker.Tests.Cases/UnreachableBlock/MethodWithParametersSubstitutions.cs#L145

What is the impact of this change - how much does it help? (just curious)

Low single digit Kb for console app but we are experimenting with more stuff for Xamarin which could benefit from this too

@marek-safar marek-safar requested a review from vitek-karas April 30, 2021 16:29
@marek-safar marek-safar merged commit 7951067 into dotnet:main May 4, 2021
@marek-safar marek-safar deleted the constprop branch May 4, 2021 04:52
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants