[llvm] [GISel] Combine vector load followed by an extractelement (PR #72670)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 27 05:51:15 PST 2023


================
@@ -1165,6 +1165,140 @@ bool CombinerHelper::findPreIndexCandidate(GLoadStore &LdSt, Register &Addr,
   return RealUse;
 }
 
+bool CombinerHelper::matchCombineExtractedVectorLoad(MachineInstr &MI) {
+  assert(MI.getOpcode() == TargetOpcode::G_EXTRACT_VECTOR_ELT);
+
+  // Check if there is a load that defines the vector being extracted from.
+  MachineInstr *LoadMI =
+      getOpcodeDef(TargetOpcode::G_LOAD, MI.getOperand(1).getReg(), MRI);
+  if (!LoadMI)
+    return false;
+
+  Register Vector = MI.getOperand(1).getReg();
+  LLT VecEltVT = MRI.getType(Vector).getElementType();
+  LLT ResultVT = MRI.getType(MI.getOperand(0).getReg());
+
+  // Do not combine when result type and vector element type are not the same.
----------------
arsenm wrote:

It can happen in SelectionDAG. We banned this in GlobalISel but I've suspected it may change as more vector handling is added 

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


More information about the llvm-commits mailing list