[llvm] [CodeGen] Do not emit TRAP for `unreachable` after `@llvm.trap` (PR #94570)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 6 03:15:25 PDT 2024
================
@@ -3076,17 +3076,17 @@ bool IRTranslator::translateUnreachable(const User &U, MachineIRBuilder &MIRBuil
return true;
auto &UI = cast<UnreachableInst>(U);
+
// We may be able to ignore unreachable behind a noreturn call.
- if (MF->getTarget().Options.NoTrapAfterNoreturn) {
- const BasicBlock &BB = *UI.getParent();
- if (&UI != &BB.front()) {
- BasicBlock::const_iterator PredI =
- std::prev(BasicBlock::const_iterator(UI));
- if (const CallInst *Call = dyn_cast<CallInst>(&*PredI)) {
- if (Call->doesNotReturn())
- return true;
- }
- }
+ if (const CallInst *Call = dyn_cast_or_null<CallInst>(UI.getPrevNode());
+ Call && Call->doesNotReturn()) {
+ if (MF->getTarget().Options.NoTrapAfterNoreturn)
+ return true;
+ // Do not emit an additional trap instruction.
+ if (Function *F = Call->getCalledFunction();
+ F && F->getIntrinsicID() == Intrinsic::trap &&
----------------
arsenm wrote:
What about the other types of traps, like ubsantrap?
https://github.com/llvm/llvm-project/pull/94570
More information about the llvm-commits
mailing list