[llvm] 71ca53b - [GlobalISel] Lower G_SHUFFLE_VECTOR with scalar result (#65275)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 4 10:32:47 PDT 2023
Author: Jay Foad
Date: 2023-09-04T13:32:43-04:00
New Revision: 71ca53b6cf097c88de5cd03232d1ccd47cf72b08
URL: https://github.com/llvm/llvm-project/commit/71ca53b6cf097c88de5cd03232d1ccd47cf72b08
DIFF: https://github.com/llvm/llvm-project/commit/71ca53b6cf097c88de5cd03232d1ccd47cf72b08.diff
LOG: [GlobalISel] Lower G_SHUFFLE_VECTOR with scalar result (#65275)
Added:
Modified:
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-shuffle-vector.mir
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 6044634bd51c9c3..cfb95955d1f888b 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -6779,26 +6779,9 @@ LegalizerHelper::lowerShuffleVector(MachineInstr &MI) {
LLT IdxTy = LLT::scalar(32);
ArrayRef<int> Mask = MI.getOperand(3).getShuffleMask();
-
- if (DstTy.isScalar()) {
- if (Src0Ty.isVector())
- return UnableToLegalize;
-
- // This is just a SELECT.
- assert(Mask.size() == 1 && "Expected a single mask element");
- Register Val;
- if (Mask[0] < 0 || Mask[0] > 1)
- Val = MIRBuilder.buildUndef(DstTy).getReg(0);
- else
- Val = Mask[0] == 0 ? Src0Reg : Src1Reg;
- MIRBuilder.buildCopy(DstReg, Val);
- MI.eraseFromParent();
- return Legalized;
- }
-
Register Undef;
SmallVector<Register, 32> BuildVec;
- LLT EltTy = DstTy.getElementType();
+ LLT EltTy = DstTy.getScalarType();
for (int Idx : Mask) {
if (Idx < 0) {
@@ -6820,7 +6803,10 @@ LegalizerHelper::lowerShuffleVector(MachineInstr &MI) {
}
}
- MIRBuilder.buildBuildVector(DstReg, BuildVec);
+ if (DstTy.isScalar())
+ MIRBuilder.buildCopy(DstReg, BuildVec[0]);
+ else
+ MIRBuilder.buildBuildVector(DstReg, BuildVec);
MI.eraseFromParent();
return Legalized;
}
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-shuffle-vector.mir b/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-shuffle-vector.mir
index d67338d7555d9dd..402454d989d6055 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-shuffle-vector.mir
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-shuffle-vector.mir
@@ -22,6 +22,53 @@ body: |
$vgpr0_vgpr1 = COPY %2
...
+
+---
+name: shufflevector_scalar_src_dst
+tracksRegLiveness: true
+
+body: |
+ bb.0:
+ liveins: $vgpr0, $vgpr1
+
+ ; CHECK-LABEL: name: shufflevector_scalar_src_dst
+ ; CHECK: liveins: $vgpr0, $vgpr1
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $vgpr0
+ ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $vgpr1
+ ; CHECK-NEXT: [[COPY2:%[0-9]+]]:_(s32) = COPY [[COPY1]](s32)
+ ; CHECK-NEXT: $vgpr0 = COPY [[COPY2]](s32)
+ %0:_(s32) = COPY $vgpr0
+ %1:_(s32) = COPY $vgpr1
+ %2:_(s32) = G_SHUFFLE_VECTOR %0, %1, shufflemask(1)
+ $vgpr0 = COPY %2
+
+...
+
+---
+name: shufflevector_scalar_dst
+tracksRegLiveness: true
+
+body: |
+ bb.0:
+ liveins: $vgpr0_vgpr1, $vgpr2_vgpr3
+
+ ; CHECK-LABEL: name: shufflevector_scalar_dst
+ ; CHECK: liveins: $vgpr0_vgpr1, $vgpr2_vgpr3
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<2 x s32>) = COPY $vgpr0_vgpr1
+ ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(<2 x s32>) = COPY $vgpr2_vgpr3
+ ; CHECK-NEXT: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[COPY1]](<2 x s32>)
+ ; CHECK-NEXT: [[COPY2:%[0-9]+]]:_(s32) = COPY [[UV]](s32)
+ ; CHECK-NEXT: [[COPY3:%[0-9]+]]:_(s32) = COPY [[COPY2]](s32)
+ ; CHECK-NEXT: $vgpr0 = COPY [[COPY3]](s32)
+ %0:_(<2 x s32>) = COPY $vgpr0_vgpr1
+ %1:_(<2 x s32>) = COPY $vgpr2_vgpr3
+ %2:_(s32) = G_SHUFFLE_VECTOR %0, %1, shufflemask(2)
+ $vgpr0 = COPY %2
+
+...
+
---
name: shufflevector_v2s32_0_1
tracksRegLiveness: true
More information about the llvm-commits
mailing list