[llvm] [NVPTX] Handle unreachable default in llvm::SwitchIns. (PR #72641)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 10:35:28 PST 2024


Artem-B wrote:

Comparing the PTX in your reproducer I do not see any interesting differences. All the code gets optimized exactly the same way, down to exactly the sane mumber of registers, so the diff is *very* clean.  The exit is not blocking any optimizations and the difference is literally one extra predicated branch to `exit` at the end of a function.

I think compiler does exactly what it should be doing and that this particular issue must be handled at the user source code level. If some switch values are truly impossible, it should be made explicit in the source code and that should allow compiler to optimize that extra jump away. Previously the code had apparently relied on UB that resulted in a cost-free fall-through through the unreachable part. If the fall-through is intentional, or impossible and we expect compiler to do something specific, the user code should be explicit about that. We should not be restoring any particular kind of undefined behavior we may have done in the past.


https://github.com/llvm/llvm-project/pull/72641


More information about the llvm-commits mailing list