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

Christian Sigg via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 28 23:50:50 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)
----------------
chsigg wrote:

```
if (!(TrapUnreachable && NoTrapAfterNoreturn))
  return TrapUnreachable;
```
... seems unnecessarily complex to save two LOCs, no?

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


More information about the llvm-commits mailing list