From 48d5dbf97283385b7509f84b6b1c063f285c559c Mon Sep 17 00:00:00 2001 From: Jon Roelofs Date: Wed, 21 Jul 2021 08:23:17 -0700 Subject: [PATCH] [MachineVerifier] Make INSERT_SUBREG diagnostic respect operand 2 subregs This came out of post-commit review: https://reviews.llvm.org/D105953#inline-1012919 Thanks uabelho! --- lib/CodeGen/MachineVerifier.cpp | 7 +++++-- test/MachineVerifier/test_insert_subreg.mir | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/MachineVerifier.cpp b/lib/CodeGen/MachineVerifier.cpp index dde0a24d90a..7e3198af02c 100644 --- a/lib/CodeGen/MachineVerifier.cpp +++ b/lib/CodeGen/MachineVerifier.cpp @@ -1783,8 +1783,11 @@ void MachineVerifier::visitMachineInstrBefore(const MachineInstr *MI) { // TODO: verify we have properly encoded deopt arguments } break; case TargetOpcode::INSERT_SUBREG: { - unsigned InsertedSize = - TRI->getRegSizeInBits(MI->getOperand(2).getReg(), *MRI); + unsigned InsertedSize; + if (unsigned SubIdx = MI->getOperand(2).getSubReg()) + InsertedSize = TRI->getSubRegIdxSize(SubIdx); + else + InsertedSize = TRI->getRegSizeInBits(MI->getOperand(2).getReg(), *MRI); unsigned SubRegSize = TRI->getSubRegIdxSize(MI->getOperand(3).getImm()); if (SubRegSize < InsertedSize) { report("INSERT_SUBREG expected inserted value to have equal or lesser " diff --git a/test/MachineVerifier/test_insert_subreg.mir b/test/MachineVerifier/test_insert_subreg.mir index f68c29edd3f..593786c73dd 100644 --- a/test/MachineVerifier/test_insert_subreg.mir +++ b/test/MachineVerifier/test_insert_subreg.mir @@ -10,7 +10,7 @@ tracksRegLiveness: true liveins: body: | bb.0: - liveins: $s0, $h1 + liveins: $s0, $h1, $q2 %0:fpr32 = COPY $s0 @@ -28,4 +28,9 @@ body: | %7:fpr128 = IMPLICIT_DEF %8:fpr128 = INSERT_SUBREG %7:fpr128, %0:fpr32, %subreg.ssub + ; CHECK-NOT: *** Bad machine code: + %9:fpr128 = COPY $q2 + %10:fpr128 = IMPLICIT_DEF + %11:fpr128 = INSERT_SUBREG %10:fpr128, %9.ssub, %subreg.ssub + ...