From 5458014282ff5977db7ccfcf3e8d1c3e68d9aefa Mon Sep 17 00:00:00 2001 From: Christian Sigg Date: Wed, 4 Oct 2023 06:05:10 +0200 Subject: [PATCH] [BACKEND] Lower to PTX with `trap-unreachable` (#2429) We've seen cases where the entire kernel is poisoned due to division-by-zero, resulting in a single `unreachable` instruction at the LLIR level. Emit this instruction as `trap` (instead of dropping it) so that the kernel doesn't run successfully without writing any outputs. --- lib/Target/PTX/PTXTranslation.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Target/PTX/PTXTranslation.cpp b/lib/Target/PTX/PTXTranslation.cpp index 3ae1bac1a..4a51cc9b3 100644 --- a/lib/Target/PTX/PTXTranslation.cpp +++ b/lib/Target/PTX/PTXTranslation.cpp @@ -88,6 +88,7 @@ std::string translateLLVMIRToPTX(llvm::Module &module, int cc, int version) { opt.UnsafeFPMath = false; opt.NoInfsFPMath = false; opt.NoNaNsFPMath = true; + opt.TrapUnreachable = true; std::unique_ptr machine{target->createTargetMachine( module.getTargetTriple(), proc, features, opt, llvm::Reloc::PIC_, std::nullopt, llvm::CodeGenOpt::Aggressive)};