[llvm] [GlobalIsel] Combine extract vector element (PR #90339)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon May 6 01:40:51 PDT 2024
================
@@ -325,6 +325,113 @@ bool CombinerHelper::matchExtractVectorElementWithBuildVectorTrunc(
return true;
}
+bool CombinerHelper::matchExtractVectorElementWithShuffleVector(
+ const MachineOperand &MO, BuildFnTy &MatchInfo) {
+ GExtractVectorElement *Extract =
+ cast<GExtractVectorElement>(getDefIgnoringCopies(MO.getReg(), MRI));
+
+ //
+ // %zero:_(s64) = G_CONSTANT i64 0
+ // %sv:_(<4 x s32>) = G_SHUFFLE_SHUFFLE %arg1(<4 x s32>), %arg2(<4 x s32>),
+ // shufflemask(0, 0, 0, 0)
+ // %extract:_(s32) = G_EXTRACT_VECTOR_ELT %sv(<4 x s32>), %zero(s64)
+ //
+ // -->
+ //
+ // %zero1:_(s64) = G_CONSTANT i64 0
+ // %extract:_(s32) = G_EXTRACT_VECTOR_ELT %arg1(<4 x s32>), %zero1(s64)
+ //
+ //
+ //
+ //
+ // %three:_(s64) = G_CONSTANT i64 3
+ // %sv:_(<4 x s32>) = G_SHUFFLE_SHUFFLE %arg1(<4 x s32>), %arg2(<4 x s32>),
+ // shufflemask(0, 0, 0, -1)
+ // %extract:_(s32) = G_EXTRACT_VECTOR_ELT %sv(<4 x s32>), %three(s64)
+ //
+ // -->
+ //
+ // %extract:_(s32) = G_IMPLICIT_DEF
+ //
+ //
+ //
+ //
+ //
+ // %sv:_(<4 x s32>) = G_SHUFFLE_SHUFFLE %arg1(<4 x s32>), %arg2(<4 x s32>),
+ // shufflemask(0, 0, 0, -1)
+ // %extract:_(s32) = G_EXTRACT_VECTOR_ELT %sv(<4 x s32>), %opaque(s64)
+ //
+ // -->
+ //
+ // %sv:_(<4 x s32>) = G_SHUFFLE_SHUFFLE %arg1(<4 x s32>), %arg2(<4 x s32>),
+ // shufflemask(0, 0, 0, -1)
+ // %extract:_(s32) = G_EXTRACT_VECTOR_ELT %sv(<4 x s32>), %opaque(s64)
+ //
+ //
+
+ // We try to get the value of the Index register.
+ std::optional<ValueAndVReg> MaybeIndex =
+ getIConstantVRegValWithLookThrough(Extract->getIndexReg(), MRI);
+ if (!MaybeIndex)
+ return false;
+
+ GShuffleVector *Shuffle =
+ cast<GShuffleVector>(getDefIgnoringCopies(Extract->getVectorReg(), MRI));
----------------
arsenm wrote:
It's unfortunate you need to re-find the def instruction when it was already matched
https://github.com/llvm/llvm-project/pull/90339
More information about the llvm-commits
mailing list