Skip to content

Commit d5c292d

Browse files
authored
[GISel][RISCV] Correctly handle scalable vector shuffles of pointer vectors in IRTranslator. (llvm#106580)
1 parent 59762a0 commit d5c292d

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,15 +3183,14 @@ bool IRTranslator::translateExtractElement(const User &U,
31833183

31843184
bool IRTranslator::translateShuffleVector(const User &U,
31853185
MachineIRBuilder &MIRBuilder) {
3186-
// A ShuffleVector that has operates on scalable vectors is a splat vector
3187-
// where the value of the splat vector is the 0th element of the first
3188-
// operand, since the index mask operand is the zeroinitializer (undef and
3186+
// A ShuffleVector that operates on scalable vectors is a splat vector where
3187+
// the value of the splat vector is the 0th element of the first operand,
3188+
// since the index mask operand is the zeroinitializer (undef and
31893189
// poison are treated as zeroinitializer here).
31903190
if (U.getOperand(0)->getType()->isScalableTy()) {
3191-
Value *Op0 = U.getOperand(0);
3191+
Register Val = getOrCreateVReg(*U.getOperand(0));
31923192
auto SplatVal = MIRBuilder.buildExtractVectorElementConstant(
3193-
LLT::scalar(Op0->getType()->getScalarSizeInBits()),
3194-
getOrCreateVReg(*Op0), 0);
3193+
MRI->getType(Val).getElementType(), Val, 0);
31953194
MIRBuilder.buildSplatVector(getOrCreateVReg(U), SplatVal);
31963195
return true;
31973196
}

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,8 +1835,8 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
18351835
break;
18361836
}
18371837

1838-
if (!SrcTy.isScalar()) {
1839-
report("Source type must be a scalar", MI);
1838+
if (!SrcTy.isScalar() && !SrcTy.isPointer()) {
1839+
report("Source type must be a scalar or pointer", MI);
18401840
break;
18411841
}
18421842

llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/shufflevector.ll

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,5 +1770,24 @@ define <vscale x 16 x i64> @shufflevector_nxv16i64_2(<vscale x 16 x i64> %a) {
17701770
ret <vscale x 16 x i64> %b
17711771
}
17721772

1773-
1774-
1773+
define <vscale x 1 x ptr> @shufflevector_nxv1p0_0() {
1774+
; RV32-LABEL: name: shufflevector_nxv1p0_0
1775+
; RV32: bb.1 (%ir-block.0):
1776+
; RV32-NEXT: [[DEF:%[0-9]+]]:_(<vscale x 1 x p0>) = G_IMPLICIT_DEF
1777+
; RV32-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
1778+
; RV32-NEXT: [[EVEC:%[0-9]+]]:_(p0) = G_EXTRACT_VECTOR_ELT [[DEF]](<vscale x 1 x p0>), [[C]](s32)
1779+
; RV32-NEXT: [[SPLAT_VECTOR:%[0-9]+]]:_(<vscale x 1 x p0>) = G_SPLAT_VECTOR [[EVEC]](p0)
1780+
; RV32-NEXT: $v8 = COPY [[SPLAT_VECTOR]](<vscale x 1 x p0>)
1781+
; RV32-NEXT: PseudoRET implicit $v8
1782+
;
1783+
; RV64-LABEL: name: shufflevector_nxv1p0_0
1784+
; RV64: bb.1 (%ir-block.0):
1785+
; RV64-NEXT: [[DEF:%[0-9]+]]:_(<vscale x 1 x p0>) = G_IMPLICIT_DEF
1786+
; RV64-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
1787+
; RV64-NEXT: [[EVEC:%[0-9]+]]:_(p0) = G_EXTRACT_VECTOR_ELT [[DEF]](<vscale x 1 x p0>), [[C]](s64)
1788+
; RV64-NEXT: [[SPLAT_VECTOR:%[0-9]+]]:_(<vscale x 1 x p0>) = G_SPLAT_VECTOR [[EVEC]](p0)
1789+
; RV64-NEXT: $v8 = COPY [[SPLAT_VECTOR]](<vscale x 1 x p0>)
1790+
; RV64-NEXT: PseudoRET implicit $v8
1791+
%a = shufflevector <vscale x 1 x ptr> poison, <vscale x 1 x ptr> poison, <vscale x 1 x i32> zeroinitializer
1792+
ret <vscale x 1 x ptr> %a
1793+
}

llvm/test/MachineVerifier/test_g_splat_vector.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ body: |
1616
; CHECK: Destination type must be a scalable vector
1717
%4:_(<2 x s32>) = G_SPLAT_VECTOR %0
1818
19-
; CHECK: Source type must be a scalar
19+
; CHECK: Source type must be a scalar or pointer
2020
%5:_(<vscale x 2 x s32>) = G_SPLAT_VECTOR %1
2121
22-
; CHECK: Source type must be a scalar
22+
; CHECK: Source type must be a scalar or pointer
2323
%6:_(<vscale x 2 x s32>) = G_SPLAT_VECTOR %2
2424
2525
; CHECK: Element type of the destination must be the same size or smaller than the source type

0 commit comments

Comments
 (0)