diff options
author | yonghong-song <yhs@fb.com> | 2025-03-20 18:18:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-20 18:18:03 -0700 |
commit | 0ffe83feaca02cf1c7a25c559c72cc16813a2f86 (patch) | |
tree | 9eacc472b7bda2232b96723a0cf713e07699ef28 /llvm/lib/CodeGen/SelectionDAG/FastISel.cpp | |
parent | 92fc748f0e6b4cc3a06b5d1de15b8b91404b7296 (diff) | |
download | llvm-0ffe83feaca02cf1c7a25c559c72cc16813a2f86.zip llvm-0ffe83feaca02cf1c7a25c559c72cc16813a2f86.tar.gz llvm-0ffe83feaca02cf1c7a25c559c72cc16813a2f86.tar.bz2 |
[SelectionDAG] Not issue TRAP node if naked function (#132147)
In [1], Nikita Popov suggested that during lowering 'unreachable' insn
should not generate extra code for naked functions, and this applies to
all architectures. Note that for naked functions, 'unreachable' insn is
necessary in IR since the basic block needs a terminator to end.
This patch checked whether a function is naked function or not. If it is
a naked function, 'unreachable' insn will not generate ISD::TRAP.
[1] https://github.com/llvm/llvm-project/pull/131731
Co-authored-by: Yonghong Song <yonghong.song@linux.dev>
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/FastISel.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/FastISel.cpp | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp index 33dd039..fbc0264 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1854,17 +1854,12 @@ bool FastISel::selectOperator(const User *I, unsigned Opcode) { } case Instruction::Unreachable: { - if (TM.Options.TrapUnreachable) { - if (TM.Options.NoTrapAfterNoreturn) { - const auto *Call = - dyn_cast_or_null<CallInst>(cast<Instruction>(I)->getPrevNode()); - if (Call && Call->doesNotReturn()) - return true; - } + auto UI = cast<UnreachableInst>(I); + if (!UI->shouldLowerToTrap(TM.Options.TrapUnreachable, + TM.Options.NoTrapAfterNoreturn)) + return true; - return fastEmit_(MVT::Other, MVT::Other, ISD::TRAP) != 0; - } - return true; + return fastEmit_(MVT::Other, MVT::Other, ISD::TRAP) != 0; } case Instruction::Alloca: |