Skip to content

Commit 681c40f

Browse files
[NVPTX] Only run LowerUnreachable on PTX version <= 7.4
1 parent 23558af commit 681c40f

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,15 @@ void NVPTXPassConfig::addIRPasses() {
368368
addPass(createSROAPass());
369369
}
370370

371-
const auto &Options = getNVPTXTargetMachine().Options;
372-
addPass(createNVPTXLowerUnreachablePass(Options.TrapUnreachable,
373-
Options.NoTrapAfterNoreturn));
371+
if (ST.getPTXVersion() <= 74) {
372+
// This pass is a WAR for a bug that's present in `ptxas` binaries that are
373+
// shipped in or prior to CUDA Toolkit 11.4. The highest version that's
374+
// supported by `ptxas` in CUDA 11.4 is 7.4. Limit this pass to only run
375+
// when targeting PTX 7.4 or lower.
376+
const auto &Options = getNVPTXTargetMachine().Options;
377+
addPass(createNVPTXLowerUnreachablePass(Options.TrapUnreachable,
378+
Options.NoTrapAfterNoreturn));
379+
}
374380
}
375381

376382
bool NVPTXPassConfig::addInstSelector() {

llvm/test/CodeGen/NVPTX/unreachable.ll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
; RUN: llc < %s -march=nvptx -mcpu=sm_20 -verify-machineinstrs \
2-
; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOTRAP
2+
; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-NOTRAP
33
; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 -verify-machineinstrs \
4-
; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOTRAP
4+
; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-NOTRAP
5+
; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 -verify-machineinstrs -mattr=+ptx75 \
6+
; RUN: | FileCheck %s --check-prefixes=CHECK-PTX75
57
; RUN: llc < %s -march=nvptx -mcpu=sm_20 -verify-machineinstrs -trap-unreachable \
6-
; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-TRAP
8+
; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-TRAP
79
; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 -verify-machineinstrs -trap-unreachable \
8-
; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-TRAP
10+
; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-TRAP
911
; RUN: %if ptxas && !ptxas-12.0 %{ llc < %s -march=nvptx -mcpu=sm_20 -verify-machineinstrs | %ptxas-verify %}
1012
; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 -verify-machineinstrs | %ptxas-verify %}
1113

@@ -21,12 +23,11 @@ define void @kernel_func() {
2123
; CHECK-TRAP: trap;
2224
; CHECK-NOTRAP-NOT: trap;
2325
; CHECK: exit;
26+
; CHECK-PTX75-NOT: exit;
2427
unreachable
2528
}
2629

2730
attributes #0 = { noreturn }
2831

29-
3032
!nvvm.annotations = !{!1}
31-
3233
!1 = !{ptr @kernel_func, !"kernel", i32 1}

0 commit comments

Comments
 (0)