diff --git a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp --- a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp +++ b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp @@ -719,6 +719,10 @@ if (MI.isDebugInstr()) continue; + // Ignore IMPLICIT_DEF which must have a regclass. + if (MI.isImplicitDef()) + continue; + if (!assignInstr(MI)) { reportGISelFailure(MF, *TPC, *MORE, "gisel-regbankselect", "unable to map instruction", MI); diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/implicit_def_rbs_crash.mir b/llvm/test/CodeGen/AArch64/GlobalISel/implicit_def_rbs_crash.mir new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/GlobalISel/implicit_def_rbs_crash.mir @@ -0,0 +1,22 @@ +# RUN: llc -O0 -mtriple arm64-- -run-pass=regbankselect -verify-machineinstrs %s -o - | FileCheck %s + +# Check we don't crash given an non-generic implicit_def. These may +# come from swifterror handling in the translator. +# CHECK: IMPLICIT_DEF +--- +name: implicit_def_crash +alignment: 4 +legalized: true +regBankSelected: false +selected: false +failedISel: false +registers: + - { id: 0, class: gpr64all, preferred-register: '' } + - { id: 1, class: _, preferred-register: '' } + - { id: 2, class: gpr64all, preferred-register: '' } + - { id: 3, class: gpr64all, preferred-register: '' } +body: | + bb.1: + %0:gpr64all = IMPLICIT_DEF + +...