[llvm] [NVPTX] Fix code generation for `trap-unreachable`. (PR #67478)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 29 10:16:00 PDT 2023


================
@@ -99,6 +105,24 @@ char NVPTXLowerUnreachable::ID = 1;
 INITIALIZE_PASS(NVPTXLowerUnreachable, "nvptx-lower-unreachable",
                 "Lower Unreachable", false, false)
 
+StringRef NVPTXLowerUnreachable::getPassName() const {
+  return "add an exit instruction before every unreachable";
+}
+
+// =============================================================================
+// Returns whether a `trap` intrinsic should be emitted before I.
+//
+// This is a copy of the logic in SelectionDAGBuilder::visitUnreachable().
+// =============================================================================
+bool NVPTXLowerUnreachable::shouldEmitTrap(const UnreachableInst &I) const {
+  if (!TrapUnreachable)
----------------
Artem-B wrote:

LLVM style tends to favor brevity, so if multiple exits do not buy us anything in terms of functionality or readability, fewer lines wins. This way you can see more code without having to scroll up/down, which does help with larger functions.

In this case it's fine either way as the function is small.

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


More information about the llvm-commits mailing list