Skip to content

Commit b2df007

Browse files
authored
[FastISel] Support unreachable with NoTrapAfterNoReturn (#118296)
Currently FastISel triggers a fallback if there is an unreachable terminator and the TrapUnreachable option is enabled (the ISD::TRAP selection does not actually work). Add handling for NoTrapAfterNoReturn, in which case we don't actually need to emit a trap. The test is just there to make sure there is no FastISel fallback (which is why I'm not testing the case without noreturn). We have other tests that check the actual unreachable codegen variations.
1 parent aec9ecb commit b2df007

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

Diff for: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -1851,11 +1851,19 @@ bool FastISel::selectOperator(const User *I, unsigned Opcode) {
18511851
return false;
18521852
}
18531853

1854-
case Instruction::Unreachable:
1855-
if (TM.Options.TrapUnreachable)
1854+
case Instruction::Unreachable: {
1855+
if (TM.Options.TrapUnreachable) {
1856+
if (TM.Options.NoTrapAfterNoreturn) {
1857+
const auto *Call =
1858+
dyn_cast_or_null<CallInst>(cast<Instruction>(I)->getPrevNode());
1859+
if (Call && Call->doesNotReturn())
1860+
return true;
1861+
}
1862+
18561863
return fastEmit_(MVT::Other, MVT::Other, ISD::TRAP) != 0;
1857-
else
1858-
return true;
1864+
}
1865+
return true;
1866+
}
18591867

18601868
case Instruction::Alloca:
18611869
// FunctionLowering has the static-sized case covered.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O0 -trap-unreachable -no-trap-after-noreturn -fast-isel-abort=3 < %s | FileCheck %s
3+
4+
declare void @foo()
5+
6+
define void @noreturn_unreachable() nounwind {
7+
; CHECK-LABEL: noreturn_unreachable:
8+
; CHECK: # %bb.0:
9+
; CHECK-NEXT: pushq %rax
10+
; CHECK-NEXT: callq foo@PLT
11+
call void @foo() noreturn
12+
unreachable
13+
}

0 commit comments

Comments
 (0)