-
Notifications
You must be signed in to change notification settings - Fork 446
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
SimplifyDefUse incorrectly removes assignment in actions with slices as arguments #2147
Comments
Just realized I was misreading my own code. The example does not remove the assignment when passing an in-value. This works as intended. |
Your first example looks like the compiler is doing the wrong thing to me. Removing any assignment to an |
I do not understand your comment that "Also I just noticed that in the first example the statement is removed even though the parameter is passed as read only." Your copy-in copy-out behavior applies to all controls, parsers, actions, functions, extern functions, and extern methods, throughout the language. The only things that are not copied-in or copied-out are directionless parameters, that I can think of right now, if they are extern objects, which are passed "by reference", sort of. |
Just updated my comment, realized I was misreading my own code. |
Sorry, I think I was misreading your initial code example.
In that code, at the time of the call to action Then you modify h.h.a inside the action. As do_action is returning, it copies the final value of val back to the caller's parameters, which is h.h.a, overwriting the assignment to h.h.a that was done inside of the action, back to its original value, because val has not been changed. So optimizing away the assignment to h.h.a inside of the do_action call does look correct to me. It isn't necessary for the compiler to do, but it is correct. |
The problem is that the def_use pass assumes that the slice assignment |
Probably the problem is with the copy-out to the slice - it does not overwrite the whole field. |
Explode every I put the smiley on that because it is for most code probably a terrible idea to do this inside the compiler's implementation, for compilation performance/memory anyway. It does have the advantage of perhaps being a simple way to make def use analysis precise down to the level of each individual bit of state. |
|
My initial diagnosis about slices was wrong; this was a bug in the modelling of function calls. |
Because of copy-out semantics, the compiler removes assignments to global variables if they are also passed as an argument.
For example:
turns into
However, when slices are passed as argument and the whole variable is modified inside the action, the statement is still removed.
turns into
and then ultimately all statements are removed. This incorrectly removes the h.h.a[0:0] = 0; assignment.
I attached a sample program and the corresponding out I would have expected. Feel free to correct me if I am making the wrong assumptions here.
slice_arg.stf.txt
slice_arg.txt
The text was updated successfully, but these errors were encountered: