[llvm] [AArch64][GlobalISel] Combine G_EXTRACT_VECTOR_ELT and G_BUILD_VECTOR sequences into G_SHUFFLE_VECTOR (PR #110545)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 22 16:10:35 PDT 2024


================
@@ -472,39 +474,16 @@ bool CombinerHelper::tryCombineShuffleVector(MachineInstr &MI) {
   return false;
 }
 
-bool CombinerHelper::matchCombineShuffleVector(MachineInstr &MI,
-                                               SmallVectorImpl<Register> &Ops) {
-  assert(MI.getOpcode() == TargetOpcode::G_SHUFFLE_VECTOR &&
-         "Invalid instruction kind");
-  LLT DstType = MRI.getType(MI.getOperand(0).getReg());
-  Register Src1 = MI.getOperand(1).getReg();
-  LLT SrcType = MRI.getType(Src1);
-  // As bizarre as it may look, shuffle vector can actually produce
-  // scalar! This is because at the IR level a <1 x ty> shuffle
-  // vector is perfectly valid.
-  unsigned DstNumElts = DstType.isVector() ? DstType.getNumElements() : 1;
-  unsigned SrcNumElts = SrcType.isVector() ? SrcType.getNumElements() : 1;
-
-  // If the resulting vector is smaller than the size of the source
-  // vectors being concatenated, we won't be able to replace the
-  // shuffle vector into a concat_vectors.
-  //
-  // Note: We may still be able to produce a concat_vectors fed by
-  //       extract_vector_elt and so on. It is less clear that would
-  //       be better though, so don't bother for now.
-  //
-  // If the destination is a scalar, the size of the sources doesn't
-  // matter. we will lower the shuffle to a plain copy. This will
-  // work only if the source and destination have the same size. But
-  // that's covered by the next condition.
-  //
-  // TODO: If the size between the source and destination don't match
-  //       we could still emit an extract vector element in that case.
-  if (DstNumElts < 2 * SrcNumElts && DstNumElts != 1)
-    return false;
+bool CombinerHelper::matchVectorMaskSequence(
----------------
ValentijnvdBeek wrote:

Added a comment and changed the name slightly, it is still a bit broad to make sure that it doesn't get pidgeonholed as just concatenation. Please tell me if you would like it to be changed 

https://github.com/llvm/llvm-project/pull/110545


More information about the llvm-commits mailing list