Skip to content

Commit 3270d98

Browse files
authored
[AArch64] Verify OPERAND_SHIFT_MSL and OPERAND_IMPLICIT_IMM_0 (#157031)
This adds some basic verification for the new OPERAND_SHIFT_MSL and the existing OPERAND_IMPLICIT_IMM_0 immediate operand types, that should be 264/272 or 0 respectively.
1 parent e1e65a4 commit 3270d98

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11276,7 +11276,6 @@ AArch64InstrInfo::analyzeLoopForPipelining(MachineBasicBlock *LoopBB) const {
1127611276
/// verifyInstruction - Perform target specific instruction verification.
1127711277
bool AArch64InstrInfo::verifyInstruction(const MachineInstr &MI,
1127811278
StringRef &ErrInfo) const {
11279-
1128011279
// Verify that immediate offsets on load/store instructions are within range.
1128111280
// Stack objects with an FI operand are excluded as they can be fixed up
1128211281
// during PEI.
@@ -11292,6 +11291,30 @@ bool AArch64InstrInfo::verifyInstruction(const MachineInstr &MI,
1129211291
}
1129311292
}
1129411293
}
11294+
11295+
const MCInstrDesc &MCID = MI.getDesc();
11296+
for (unsigned Op = 0; Op < MCID.getNumOperands(); Op++) {
11297+
const MachineOperand &MO = MI.getOperand(Op);
11298+
switch (MCID.operands()[Op].OperandType) {
11299+
case AArch64::OPERAND_IMPLICIT_IMM_0:
11300+
if (!MO.isImm() || MO.getImm() != 0) {
11301+
ErrInfo = "OPERAND_IMPLICIT_IMM_0 should be 0";
11302+
return false;
11303+
}
11304+
break;
11305+
case AArch64::OPERAND_SHIFT_MSL:
11306+
if (!MO.isImm() ||
11307+
AArch64_AM::getShiftType(MO.getImm()) != AArch64_AM::MSL ||
11308+
(AArch64_AM::getShiftValue(MO.getImm()) != 8 &&
11309+
AArch64_AM::getShiftValue(MO.getImm()) != 16)) {
11310+
ErrInfo = "OPERAND_SHIFT_MSL should be msl shift of 8 or 16";
11311+
return false;
11312+
}
11313+
break;
11314+
default:
11315+
break;
11316+
}
11317+
}
1129511318
return true;
1129611319
}
1129711320

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# RUN: not --crash llc -mtriple=aarch64 -run-pass machineverifier -o /dev/null %s 2>&1 | FileCheck -implicit-check-not="Bad machine code" %s
2+
3+
# CHECK: *** Bad machine code: OPERAND_SHIFT_MSL should be msl shift of 8 or 16 ***
4+
# CHECK: - instruction: $d0 = MOVIv2s_msl 55, 262
5+
# CHECK: *** Bad machine code: OPERAND_SHIFT_MSL should be msl shift of 8 or 16 ***
6+
# CHECK: - instruction: $q0 = MOVIv4s_msl 55, 8
7+
# CHECK: *** Bad machine code: OPERAND_IMPLICIT_IMM_0 should be 0 ***
8+
# CHECK: - instruction: $zad0 = MOVA_MXI2Z_V_D $zad0(tied-def 0), $w12, 1, $z0_z1
9+
10+
---
11+
name: verifyImm
12+
alignment: 4
13+
tracksRegLiveness: true
14+
body: |
15+
bb.0.entry:
16+
liveins: $z0_z1, $zad0, $x0, $w12
17+
18+
$d0 = MOVIv2s_msl 55, 262
19+
$q0 = MOVIv4s_msl 55, 8
20+
$zad0 = MOVA_MXI2Z_V_D $zad0, $w12, 1, $z0_z1
21+
RET undef $lr, implicit $x0
22+
...

0 commit comments

Comments
 (0)