[llvm] [AArch64][GlobalISel] Add combine for build_vector(unmerge, unmerge, undef, undef) (PR #165539)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 30 18:02:38 PDT 2025
================
@@ -133,6 +134,123 @@ bool isZeroExtended(Register R, MachineRegisterInfo &MRI) {
return MRI.getVRegDef(R)->getOpcode() == TargetOpcode::G_ZEXT;
}
+// This pattern aims to match the following shape to avoid extra mov
+// instructions
+// G_BUILD_VECTOR(
+// G_UNMERGE_VALUES(src, 0)
+// G_UNMERGE_VALUES(src, 1)
+// G_IMPLICIT_DEF
+// G_IMPLICIT_DEF
+// )
+// ->
+// G_CONCAT_VECTORS(
+// src,
+// undef
+// )
+bool matchCombineBuildUnmerge(MachineInstr &MI, MachineRegisterInfo &MRI,
+ Register &UnmergeSrc) {
+ assert(MI.getOpcode() == TargetOpcode::G_BUILD_VECTOR);
+
+ unsigned UnmergeUseCount = 0;
+ unsigned UndefInstrCount = 0;
+
+ unsigned UnmergeEltCount = 0;
+ unsigned UnmergeEltSize = 0;
+
+ unsigned BuildOperandCount = MI.getNumOperands();
+ bool EncounteredUndef = false;
+
+ Register UnmergeSrcTemp;
+ MachineInstr *UnmergeInstr;
+
+ std::set<int> KnownRegs;
+
+ for (auto &Use : MI.all_uses()) {
+ auto *Def = getDefIgnoringCopies(Use.getReg(), MRI);
+
+ if (!Def) {
----------------
arsenm wrote:
This should not be possible
https://github.com/llvm/llvm-project/pull/165539
More information about the llvm-commits
mailing list