From: Eli Friedman Date: Fri, 15 Mar 2019 21:44:49 +0000 (+0000) Subject: [ARM] Add MachineVerifier logic for some Thumb1 instructions. X-Git-Tag: llvmorg-10-init~9838 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=68d9a60573fad118225d5e19303132f75c389936;p=platform%2Fupstream%2Fllvm.git [ARM] Add MachineVerifier logic for some Thumb1 instructions. tMOVr and tPUSH/tPOP/tPOP_RET have register constraints which can't be expressed in TableGen, so check them explicitly. I've unfortunately run into issues with both of these recently; hopefully this saves some time for someone else in the future. Differential Revision: https://reviews.llvm.org/D59383 llvm-svn: 356303 --- diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp index eaa8995..3250ee5 100644 --- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp +++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp @@ -4570,6 +4570,31 @@ bool ARMBaseInstrInfo::verifyInstruction(const MachineInstr &MI, ErrInfo = "Pseudo flag setting opcodes only exist in Selection DAG"; return false; } + if (MI.getOpcode() == ARM::tMOVr && !Subtarget.hasV6Ops()) { + // Make sure we don't generate a lo-lo mov that isn't supported. + if (!ARM::hGPRRegClass.contains(MI.getOperand(0).getReg()) && + !ARM::hGPRRegClass.contains(MI.getOperand(1).getReg())) { + ErrInfo = "Non-flag-setting Thumb1 mov is v6-only"; + return false; + } + } + if (MI.getOpcode() == ARM::tPUSH || + MI.getOpcode() == ARM::tPOP || + MI.getOpcode() == ARM::tPOP_RET) { + for (int i = 2, e = MI.getNumOperands(); i < e; ++i) { + if (MI.getOperand(i).isImplicit() || + !MI.getOperand(i).isReg()) + continue; + unsigned Reg = MI.getOperand(i).getReg(); + if (Reg < ARM::R0 || Reg > ARM::R7) { + if (!(MI.getOpcode() == ARM::tPUSH && Reg == ARM::LR) && + !(MI.getOpcode() == ARM::tPOP_RET && Reg == ARM::PC)) { + ErrInfo = "Unsupported register in Thumb1 push/pop"; + return false; + } + } + } + } return true; } diff --git a/llvm/test/CodeGen/ARM/machine-verifier.mir b/llvm/test/CodeGen/ARM/machine-verifier.mir new file mode 100644 index 0000000..c5d678c --- /dev/null +++ b/llvm/test/CodeGen/ARM/machine-verifier.mir @@ -0,0 +1,22 @@ +# RUN: not llc -mtriple=thumb -run-pass none -o /dev/null %s 2>&1 | FileCheck %s +# This test ensures that the MIR parser runs the machine verifier after parsing. + +--- | + + define i32 @inc(i32 %a) { + entry: + ret i32 %a + } + +... +--- +name: inc +tracksRegLiveness: true +body: | + bb.0.entry: + ; CHECK: *** Bad machine code: Unsupported register in Thumb1 push/pop *** + frame-setup tPUSH 14, $noreg, undef $r12, killed $lr, implicit-def $sp, implicit $sp + + ; CHECK: *** Bad machine code: Non-flag-setting Thumb1 mov is v6-only *** + $r2 = tMOVr killed $r6, 14, $noreg +...