[llvm] 79d13bf - Revert "Revert "[GlobalISel][IRTranslator] Emit trap intrinsic for "unreachable"""
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 6 04:16:24 PDT 2021
Author: Amara Emerson
Date: 2021-10-06T04:16:19-07:00
New Revision: 79d13bf22c169cf83515e799d45db8d6424104fd
URL: https://github.com/llvm/llvm-project/commit/79d13bf22c169cf83515e799d45db8d6424104fd
DIFF: https://github.com/llvm/llvm-project/commit/79d13bf22c169cf83515e799d45db8d6424104fd.diff
LOG: Revert "Revert "[GlobalISel][IRTranslator] Emit trap intrinsic for "unreachable"""
This reverts commit d95cd81141a4e398e0d3337cb2e6617281d06278.
Re-land the original patch now that the bug this exposed in selection has been
fixed by 6bc64e24c38a
Added:
llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-unreachable.ll
Modified:
llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
index b11281b819df9..ebe16cd4f58c5 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
@@ -467,9 +467,8 @@ class IRTranslator : public MachineFunctionPass {
bool translateSIToFP(const User &U, MachineIRBuilder &MIRBuilder) {
return translateCast(TargetOpcode::G_SITOFP, U, MIRBuilder);
}
- bool translateUnreachable(const User &U, MachineIRBuilder &MIRBuilder) {
- return true;
- }
+ bool translateUnreachable(const User &U, MachineIRBuilder &MIRBuilder);
+
bool translateSExt(const User &U, MachineIRBuilder &MIRBuilder) {
return translateCast(TargetOpcode::G_SEXT, U, MIRBuilder);
}
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 87d9e240fdef0..f33eac4f4a4f5 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2701,6 +2701,28 @@ bool IRTranslator::translateVAArg(const User &U, MachineIRBuilder &MIRBuilder) {
return true;
}
+bool IRTranslator::translateUnreachable(const User &U, MachineIRBuilder &MIRBuilder) {
+ if (!MF->getTarget().Options.TrapUnreachable)
+ 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;
+ }
+ }
+ }
+
+ MIRBuilder.buildIntrinsic(Intrinsic::trap, ArrayRef<Register>(), true);
+ return true;
+}
+
bool IRTranslator::translateInsertElement(const User &U,
MachineIRBuilder &MIRBuilder) {
// If it is a <1 x Ty> vector, use the scalar as it is
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-unreachable.ll b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-unreachable.ll
new file mode 100644
index 0000000000000..fe9427d2678a1
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-unreachable.ll
@@ -0,0 +1,24 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+; RUN: llc -O0 -mtriple=aarch64-apple-ios -global-isel -stop-after=irtranslator %s -o - | FileCheck %s
+
+declare void @llvm.trap()
+
+define void @unreachable() {
+ ; CHECK-LABEL: name: unreachable
+ ; CHECK: bb.1 (%ir-block.0):
+ ; CHECK-NEXT: G_INTRINSIC_W_SIDE_EFFECTS intrinsic(@llvm.trap)
+ unreachable
+ ret void
+}
+
+declare void @foo() noreturn
+define void @trap_call_noreturn() {
+ ; CHECK-LABEL: name: trap_call_noreturn
+ ; CHECK: bb.1 (%ir-block.0):
+ ; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
+ ; CHECK-NEXT: BL @foo, csr_darwin_aarch64_aapcs, implicit-def $lr, implicit $sp
+ ; CHECK-NEXT: ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
+ call void @foo()
+ unreachable
+ ret void
+}
More information about the llvm-commits
mailing list