[llvm] [GlobalISel] Fold G_SHUFFLE_VECTOR with a single element mask to G_EXTRACT_VECTOR_ELT (PR #65342)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 5 09:14:40 PDT 2023
================
@@ -395,6 +395,44 @@ void CombinerHelper::applyCombineShuffleVector(MachineInstr &MI,
replaceRegWith(MRI, DstReg, NewDstReg);
}
+bool CombinerHelper::matchShuffleToExtract(MachineInstr &MI) {
+ assert(MI.getOpcode() == TargetOpcode::G_SHUFFLE_VECTOR &&
+ "Invalid instruction kind");
+ ArrayRef<int> Mask = MI.getOperand(3).getShuffleMask();
+ LLT Src1Ty = MRI.getType(MI.getOperand(1).getReg());
+ LLT Src2Ty = MRI.getType(MI.getOperand(2).getReg());
+ int Src1NumElts = Src1Ty.isVector() ? Src1Ty.getNumElements() : 1;
+ int Src2NumElts = Src2Ty.isVector() ? Src2Ty.getNumElements() : 1;
+
+ return Mask.size() == 1 && Mask[0] >= 0 &&
----------------
jayfoad wrote:
You don't really need to check things that are already enforced by MachineVerifier. All you need here is `Mask.size() == 1 && Mask[0] >= 0`.
https://github.com/llvm/llvm-project/pull/65342
More information about the llvm-commits
mailing list