Skip to content

Commit ddba0ff

Browse files
[GISEL] G_SPLAT_VECTOR can take a splat that is smaller than the vector element
This is what SelectionDAG does. We'd like to reuse SelectionDAG patterns.
1 parent 1a4eb6e commit ddba0ff

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

llvm/docs/GlobalISel/GenericOpcode.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,10 @@ G_SPLAT_VECTOR
690690

691691
Create a vector where all elements are the scalar from the source operand.
692692

693+
The type of the operand must be equal to or larger than the vector element
694+
type. If the operand is larger than the vector element type, the scalar is
695+
implicitly truncated to the vector element type.
696+
693697
Vector Reduction Operations
694698
---------------------------
695699

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,16 +1768,23 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
17681768
LLT DstTy = MRI->getType(MI->getOperand(0).getReg());
17691769
LLT SrcTy = MRI->getType(MI->getOperand(1).getReg());
17701770

1771-
if (!DstTy.isScalableVector())
1771+
if (!DstTy.isScalableVector()) {
17721772
report("Destination type must be a scalable vector", MI);
1773+
break;
1774+
}
17731775

1774-
if (!SrcTy.isScalar())
1776+
if (!SrcTy.isScalar()) {
17751777
report("Source type must be a scalar", MI);
1778+
break;
1779+
}
17761780

1777-
if (DstTy.getScalarType() != SrcTy)
1778-
report("Element type of the destination must be the same type as the "
1779-
"source type",
1781+
if (TypeSize::isKnownGT(DstTy.getScalarType().getSizeInBits(),
1782+
SrcTy.getSizeInBits())) {
1783+
report("Element type of the destination must be the same size or smaller "
1784+
"than the source type",
17801785
MI);
1786+
break;
1787+
}
17811788

17821789
break;
17831790
}

llvm/test/MachineVerifier/test_g_splat_vector.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ body: |
2222
; CHECK: Source type must be a scalar
2323
%6:_(<vscale x 2 x s32>) = G_SPLAT_VECTOR %2
2424
25-
; CHECK: Element type of the destination must be the same type as the source type
26-
%7:_(<vscale x 2 x s64>) = G_SPLAT_VECTOR %0
25+
; CHECK: Element type of the destination must be the same size or smaller than the source type
26+
%7:_(<vscale x 2 x s128>) = G_SPLAT_VECTOR %0
2727
...

0 commit comments

Comments
 (0)