[llvm] [NVPTX] Only run LowerUnreachable when necessary (PR #109868)
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 30 10:58:56 PDT 2024
Artem-B wrote:
To me it looks like there are two things we need to decide here:
* Can ptxas guarantee that it can handle unstructured CFG in principle? My recollection from the time when we initially struggled wit this issue is that it's not always possible. The nature of "unreachable" code in generated PTX is that it can result in unpredictable phantom CFG edges (as far as ptxas is concerned). Explicitly marking unreachable code with something that allows us to propagate that information to ptxas looks like something that we need to do. `trap`, AFAICT, is the best way to do so that we have right now.
The downside of this approach is that it is an extra instruction and, I believe, there were some reported use cases where it resulted in performance regressions in user code.
Ideally, it would be nice if ptxas would provide a NOP-like equivalent of `unreachable`, which would preserve correctness of its view of CFG without generating any extra instructions.
* generation of `trap; exit;` is a workaround for the bug in the older ptxas which did not consider `trap` by itself as a CFG leaf. Whether we emit it or not would depend on whether we want/need to emit the unreachable hint instruction to PTX, and, if we do, or on the PTX (or ptxas) version.
https://github.com/llvm/llvm-project/pull/109868
More information about the llvm-commits
mailing list