-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
[clang] Missed optimization: Failure to remove useless allocations / deallocations #122567
Comments
When OOM occurs at
If we ignore this call, we will get an expected result: https://godbolt.org/z/K1r97GPxj
But SimplifyCFG is not allowed to sink the call to |
Similarly, OOM may occur at the second |
Moving it is one way to do this, and would be allowed as long as we're smart about not calling it twice. The observable behavior remains the same, because the standard allows the implementation to change the when and where Another option is to recognize that if an exception is thrown, the memory is deallocated immediately after the call, and if an exception is not thrown, the memory is deallocated immediately after the call. So the first allocation cannot escape the function and can thus be elided entirely so long as we can use other optimizations to do writes to the final memory destination. It's also interesting to note that removing the line |
One last thing to note about the existing code gen for |
They are referenced by the section |
The following translation unit:
when compiled with
-O3
generates the following output:which corresponds to the assembly
I want it to generate
which corresponds to
It looks like if an optimization pass implemented #68365 that would be sufficient to solve this problem, but there are other possible optimization paths for this.
See it live: https://godbolt.org/z/r87Ezb8b5
This bug prevents the optimization of the following code with any standard library implementation:
The text was updated successfully, but these errors were encountered: