-
Notifications
You must be signed in to change notification settings - Fork 445
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
Inlining functions can be optimized to avoid copy-in copy-out when possible #2470
Comments
In either case you get an undefined result. |
It definitely seems like this is a case where the compiler is transforming the I do not currently have any strong opinions on whether compiler transformations should maximally preserve undefined behavior, or should be allowed to reduce the possible behaviors. |
Perhaps it's a bug, I will investigate further. |
For what it's worth, I cannot think of a case where this could be harmful. What I found odd was the difference in behaviour between function/action inlining and control inlining. |
The inliner for controls is slightly better optimized: it tries to avoid doing copy-in copy-out when the arguments to not alias or have side-effects. The function inliner always does copy-in copy-out. So I guess this is an optimization opportunity for functions, where we can reuse some of the code for the controls. I will rename this issue to reflect this fact, and mark it as an enhacement. This may help with actions too. |
This is something I have observed in an actual large P4 program.
So I have the following snippet:
After the inlining passes (Inline and InlineFunctions), this turns into:
In this case, the semantics of the out parameter for the function call are preserved, but not for the control
apply()
statement. Which one is correct? Or are both okay? One could argue that not changing the input value at all is a subset of undefined behaviour. Still, this seems inconsistent.control_nested_inline.p4.txt
The text was updated successfully, but these errors were encountered: