Skip to content

Commit e494e2a

Browse files
authored
[MachineVerifier] Improve G_EXTRACT_SUBVECTOR checking (#109202)
Check that the destination of G_EXTRACT_SUBVECTOR is smaller than the source. Improve wording of error messages.
1 parent d21a435 commit e494e2a

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
17691769
}
17701770

17711771
if (!SrcTy.isVector()) {
1772-
report("First source must be a vector", MI);
1772+
report("Source must be a vector", MI);
17731773
break;
17741774
}
17751775

@@ -1783,6 +1783,12 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
17831783
break;
17841784
}
17851785

1786+
if (ElementCount::isKnownGT(DstTy.getElementCount(),
1787+
SrcTy.getElementCount())) {
1788+
report("Destination vector must be smaller than source vector", MI);
1789+
break;
1790+
}
1791+
17861792
uint64_t Idx = IndexOp.getImm();
17871793
uint64_t DstMinLen = DstTy.getElementCount().getKnownMinValue();
17881794
if (Idx % DstMinLen != 0) {
@@ -1793,10 +1799,9 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
17931799
}
17941800

17951801
uint64_t SrcMinLen = SrcTy.getElementCount().getKnownMinValue();
1796-
if (SrcTy.isScalable() == DstTy.isScalable() &&
1797-
(Idx >= SrcMinLen || Idx + DstMinLen > SrcMinLen)) {
1798-
report("Source type and index must not cause extract to overrun to the "
1799-
"destination type",
1802+
if (Idx >= SrcMinLen || Idx + DstMinLen > SrcMinLen) {
1803+
report("Destination type and index must not cause extract to overrun the "
1804+
"source vector",
18001805
MI);
18011806
break;
18021807
}

llvm/test/MachineVerifier/test_g_extract_subvector.mir

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ body: |
1010
%1:_(<vscale x 2 x s32>) = G_IMPLICIT_DEF
1111
%2:_(<vscale x 1 x s32>) = G_IMPLICIT_DEF
1212
13+
; CHECK: generic instruction must use register operands
1314
; CHECK: G_EXTRACT_SUBVECTOR first source must be a register
1415
%3:_(<vscale x 2 x s32>) = G_EXTRACT_SUBVECTOR 1, 0
1516
@@ -19,35 +20,35 @@ body: |
1920
; CHECK: Destination type must be a vector
2021
%5:_(s32) = G_EXTRACT_SUBVECTOR %2, 0
2122
22-
; CHECK: First source must be a vector
23+
; CHECK: Source must be a vector
2324
%6:_(<vscale x 2 x s32>) = G_EXTRACT_SUBVECTOR %0, 0
2425
2526
%7:_(<vscale x 1 x s16>) = G_IMPLICIT_DEF
2627
2728
; CHECK: Element type of vectors must be the same
2829
%8:_(<vscale x 2 x s32>) = G_EXTRACT_SUBVECTOR %7, 0
2930
30-
; CHECK: Index must be a multiple of the destination vector's minimum vector length
31+
; CHECK: Destination vector must be smaller than source vector
3132
%9:_(<vscale x 4 x s32>) = G_EXTRACT_SUBVECTOR %1, 3
3233
33-
; CHECK: Index must be a multiple of the destination vector's minimum vector length
34+
; CHECK: Destination vector must be smaller than source vector
3435
%10:_(<vscale x 4 x s32>) = G_EXTRACT_SUBVECTOR %1, 2
3536
36-
; CHECK: Source type and index must not cause extract to overrun to the destination type
37+
; CHECK: Destination type and index must not cause extract to overrun the source vector
3738
%11:_(<vscale x 1 x s32>) = G_EXTRACT_SUBVECTOR %1, 4
3839
3940
%12:_(<vscale x 4 x s32>) = G_IMPLICIT_DEF
4041
41-
; CHECK: Source type and index must not cause extract to overrun to the destination type
42+
; CHECK: Destination type and index must not cause extract to overrun the source vector
4243
%13:_(<vscale x 3 x s32>) = G_EXTRACT_SUBVECTOR %12, 3
4344
4445
%14:_(<2 x s32>) = G_IMPLICIT_DEF
4546
%15:_(<4 x s32>) = G_IMPLICIT_DEF
4647
47-
; CHECK: Source type and index must not cause extract to overrun to the destination type
48+
; CHECK: Destination type and index must not cause extract to overrun the source vector
4849
%16:_(<2 x s32>) = G_EXTRACT_SUBVECTOR %14, 4
4950
50-
; CHECK: Source type and index must not cause extract to overrun to the destination type
51+
; CHECK: Destination type and index must not cause extract to overrun the source vector
5152
%17:_(<3 x s32>) = G_EXTRACT_SUBVECTOR %15, 3
5253
5354
; CHECK: Vector types must both be fixed or both be scalable
@@ -56,5 +57,7 @@ body: |
5657
; CHECK: Vector types must both be fixed or both be scalable
5758
%19:_(<2 x s32>) = G_EXTRACT_SUBVECTOR %12, 0
5859
60+
; CHECK: Index must be a multiple of the destination vector's minimum vector length
61+
%20:_(<vscale x 2 x s32>) = G_EXTRACT_SUBVECTOR %12, 1
5962
6063
...

0 commit comments

Comments
 (0)