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
[asm goto] support outputs along indirect branches #53562
Comments
@llvm/issue-subscribers-clang-codegen |
Outputs are only valid on the fallthrough codepath; on other paths, the output values are ignored. That's by design. Or at least, it's a practical consequence of the way asm goto is currently implemented. This is documented at https://clang.llvm.org/docs/LanguageExtensions.html#asm-goto-with-output-constraints . -Wuninitialized prints a warning for your testcase. The warning could probably be improved. Not sure what else we can do here. |
Okay, I see what happened. This part of that documentation is no longer quite accurate:
Because as of version 11.1.0 (specifically, commit |
cc @jyknight @gwelymernans @isanbard
Yeah, we probably can't focus on this for a couple months, but this is surely a portability issue that folks will begin to notice more and more frequently. We'll probably need to undo parts of https://reviews.llvm.org/D79794, making Also, there is one undesirable side effect where address of label would no longer refer to the same label as the |
If GCC's able to allow outputs on indirect branches, then they must not care about the label addresses like we did. (Segher mentioned something along those lines in our discussions with him before the implementation.) That would take care of the vast majority of issues we faced with splitting critical edges. I don't know if it's worth making |
Updating docs to make note of this difference https://reviews.llvm.org/D135818. Will need to revisit those docs when this is implemented. |
…om GCC That said, we are planning to add this support in the near future. Link: #53562 Differential Revision: https://reviews.llvm.org/D135818
Capstone of https://discourse.llvm.org/t/rfc-syncing-asm-goto-with-outputs-with-gcc/65453/8 Clang changes are still necessary to enable the use of outputs along indirect edges of asm goto statements. Link: #53562 Reviewed By: void Differential Revision: https://reviews.llvm.org/D140180
Now that we support outputs from asm goto along indirect edges, we can remove/revert some code that was added to help warn about the previous limitation that outputs were not supported along indirect edges. Reverts some code added in: commit 72aa619 ("Warn of uninitialized variables on asm goto's indirect branch") commit 3a604fd ("[Clang][CFG] check children statements of asm goto") But keeps+updates the tests. Link: #53562 Reviewed By: void Differential Revision: https://reviews.llvm.org/D140508
Landed as:
This is intentionally going to ship in clang-17; I want it to miss the clang-16 train so that it gets maximal soak time. @josephcsible please help test using ToT. @nathanchance is going to help me keep an eye on this in case we need to revert/back it out (hence the above list, in case it's needed). Please file new bugs and assign to me for issues found with this feature. |
Capstone of https://discourse.llvm.org/t/rfc-syncing-asm-goto-with-outputs-with-gcc/65453/8 Clang changes are still necessary to enable the use of outputs along indirect edges of asm goto statements. Link: llvm/llvm-project#53562 Reviewed By: void Differential Revision: https://reviews.llvm.org/D140180
Initial support for asm goto w/ outputs (D69876) only supported outputs along the "default" (aka "fallthrough") edge. We can support outputs along all edges by repeating the same pattern of stores along the indirect edges that we allready do for the default edge. One complication is that these indirect edges may be critical edges which would need to be split. Another issue is that mid-codgen of LLVM IR, the control flow graph might not reflect the control flow of the final function. To avoid this "chicken and the egg" problem assume that any given indirect edge may become a critical edge, and pro-actively split it. This is unnecessary if the edge does not become critical, but LLVM will optimize such cases via tail duplication. Fixes: llvm/llvm-project#53562 Reviewed By: void Differential Revision: https://reviews.llvm.org/D136497
Now that we support outputs from asm goto along indirect edges, we can remove/revert some code that was added to help warn about the previous limitation that outputs were not supported along indirect edges. Reverts some code added in: commit 72aa619 ("Warn of uninitialized variables on asm goto's indirect branch") commit 3a604fd ("[Clang][CFG] check children statements of asm goto") But keeps+updates the tests. Link: llvm/llvm-project#53562 Reviewed By: void Differential Revision: https://reviews.llvm.org/D140508
Huzzah!!! Great job. :-) |
I broke it with the exact same code as in my first post here |
Another follow up reported issue: #61023 |
…EASM_BR When generating spills (stores) for values produced by INLINEASM_BR instructions, make sure to insert one spill per indirect target. Otherwise the reload generated may load from a stack slot that has not yet been stored to (resulting in a load of an uninitialized stack slot). Link: #53562 Fixes: #60855 Reviewed By: MatzeB Differential Revision: https://reviews.llvm.org/D144907
This isn't safe to do. Link: #53562 Fixes: #61023 Reviewed By: efriedma, nikic Differential Revision: https://reviews.llvm.org/D144927
This isn't safe to do. Link: llvm/llvm-project#53562 Fixes: llvm/llvm-project#61023 Reviewed By: efriedma, nikic Differential Revision: https://reviews.llvm.org/D144927
This isn't safe to do. Link: llvm/llvm-project#53562 Fixes: llvm/llvm-project#61023 Reviewed By: efriedma, nikic Differential Revision: https://reviews.llvm.org/D144927
This isn't safe to do. Link: llvm#53562 Fixes: llvm#61023 Reviewed By: efriedma, nikic Differential Revision: https://reviews.llvm.org/D144927
Consider this C code:
It's supposed to return 45. But when you compile it in Clang, it returns 123 instead. I tested this on both trunk (01b52f7) and 13.0.0, and both with -O3 and without optimizations, and the bug happens in all of those cases.
https://godbolt.org/z/vKeYrfYY5
The text was updated successfully, but these errors were encountered: