[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
Wed Sep 6 04:58:55 PDT 2023
================
@@ -395,6 +395,39 @@ 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();
+ return Mask.size() == 1 && Mask[0] >= 0;
+}
+
+void CombinerHelper::applyShuffleToExtract(MachineInstr &MI) {
+ Register DstReg = MI.getOperand(0).getReg();
+ Builder.setInsertPt(*MI.getParent(), MI);
+ Register NewDstReg = MRI.cloneVirtualRegister(DstReg);
----------------
jayfoad wrote:
You should be able to build instructions that write to DstReg, instead of creating NewDstReg and then calling replaceRegWith. Unless I'm missing something.
https://github.com/llvm/llvm-project/pull/65342
More information about the llvm-commits
mailing list