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

Amara Emerson via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 28 23:15:35 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.
----------------
aemerson wrote:

Maybe just add an assert so that we immediately crash if this assumption is violated.

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


More information about the llvm-commits mailing list