Skip to content

Commit 4d15b66

Browse files
committed
[GISel] Improve MachineVerifier for G_SCMP/UCMP.
Ensure destination type is at least 2 bytes. Remove unnecessary check that both sources are the same type. The verifier already handles this generically.
1 parent 1464b8e commit 4d15b66

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,9 +1615,8 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
16151615
case TargetOpcode::G_UCMP: {
16161616
LLT DstTy = MRI->getType(MI->getOperand(0).getReg());
16171617
LLT SrcTy = MRI->getType(MI->getOperand(1).getReg());
1618-
LLT SrcTy2 = MRI->getType(MI->getOperand(2).getReg());
16191618

1620-
if (SrcTy.isPointerOrPointerVector() || SrcTy2.isPointerOrPointerVector()) {
1619+
if (SrcTy.isPointerOrPointerVector()) {
16211620
report("Generic scmp/ucmp does not support pointers as operands", MI);
16221621
break;
16231622
}
@@ -1627,18 +1626,18 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
16271626
break;
16281627
}
16291628

1629+
if (DstTy.getScalarSizeInBits() < 2) {
1630+
report("result type must be at least 2 bits wide", MI);
1631+
break;
1632+
}
1633+
16301634
if ((DstTy.isVector() != SrcTy.isVector()) ||
16311635
(DstTy.isVector() &&
16321636
DstTy.getElementCount() != SrcTy.getElementCount())) {
16331637
report("Generic vector scmp/ucmp must preserve number of lanes", MI);
16341638
break;
16351639
}
16361640

1637-
if (SrcTy != SrcTy2) {
1638-
report("Generic scmp/ucmp must have same input types", MI);
1639-
break;
1640-
}
1641-
16421641
break;
16431642
}
16441643
case TargetOpcode::G_EXTRACT: {

llvm/test/MachineVerifier/test_uscmp.mir

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ body: |
1919
%23:_(<2 x s32>) = G_IMPLICIT_DEF
2020
%24:_(<2 x s32>) = G_IMPLICIT_DEF
2121
; CHECK: Generic vector scmp/ucmp must preserve number of lanes
22-
%5:_(s1) = G_UCMP %23, %24
22+
%5:_(s2) = G_UCMP %23, %24
2323
2424
%15:_(s32) = G_CONSTANT i32 0
2525
%16:_(s64) = G_CONSTANT i64 2
26-
; CHECK: Generic scmp/ucmp must have same input types
27-
%17:_(s1) = G_SCMP %15, %16
26+
; CHECK: Type mismatch in generic instruction
27+
%17:_(s2) = G_SCMP %15, %16
2828
29+
%18:_(s32) = G_CONSTANT i32 0
30+
%19:_(s32) = G_CONSTANT i32 2
31+
; CHECK: result type must be at least 2 bits wide
32+
%20:_(s1) = G_SCMP %18, %19
2933
3034
3135
...

0 commit comments

Comments
 (0)