Skip to content

[FastISel] Support unreachable with NoTrapAfterNoReturn #118296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1851,11 +1851,19 @@ bool FastISel::selectOperator(const User *I, unsigned Opcode) {
return false;
}

case Instruction::Unreachable:
if (TM.Options.TrapUnreachable)
case Instruction::Unreachable: {
if (TM.Options.TrapUnreachable) {
if (TM.Options.NoTrapAfterNoreturn) {
const auto *Call =
dyn_cast_or_null<CallInst>(cast<Instruction>(I)->getPrevNode());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CallBase?

if (Call && Call->doesNotReturn())
return true;
}

return fastEmit_(MVT::Other, MVT::Other, ISD::TRAP) != 0;
else
return true;
}
return true;
}

case Instruction::Alloca:
// FunctionLowering has the static-sized case covered.
Expand Down
13 changes: 13 additions & 0 deletions llvm/test/CodeGen/X86/no-trap-after-noreturn-fastisel.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O0 -trap-unreachable -no-trap-after-noreturn -fast-isel-abort=3 < %s | FileCheck %s

declare void @foo()

define void @noreturn_unreachable() nounwind {
; CHECK-LABEL: noreturn_unreachable:
; CHECK: # %bb.0:
; CHECK-NEXT: pushq %rax
; CHECK-NEXT: callq foo@PLT
call void @foo() noreturn
unreachable
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check invoke case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invoke is a terminator, so it can't be followed by unreachable. (Same is true for callbr.)

Loading