Skip to content

Commit

Permalink
[AArch64][GlobalISel] Lower G_EXTRACT_VECTOR_ELT with variable indices
Browse files Browse the repository at this point in the history
G_EXTRACT_VECTOR_ELT instructions with non-constant indices are not
selected, so they need to be lowered.

Fixes #65049.

Reviewed By: Peter

Differential Revision: https://reviews.llvm.org/D159096
  • Loading branch information
dzhidzhoev committed Sep 4, 2023
1 parent bb94817 commit a15144f
Show file tree
Hide file tree
Showing 4 changed files with 643 additions and 23 deletions.
18 changes: 15 additions & 3 deletions llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,11 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
return Query.Types[0] != EltTy;
})
.minScalar(2, s64)
.legalIf([=](const LegalityQuery &Query) {
.customIf([=](const LegalityQuery &Query) {
const LLT &VecTy = Query.Types[1];
return VecTy == v2s16 || VecTy == v4s16 || VecTy == v8s16 ||
VecTy == v4s32 || VecTy == v2s64 || VecTy == v2s32 ||
VecTy == v8s8 || VecTy == v16s8 || VecTy == v2s32 ||
VecTy == v2p0;
VecTy == v8s8 || VecTy == v16s8 || VecTy == v2p0;
})
.minScalarOrEltIf(
[=](const LegalityQuery &Query) {
Expand Down Expand Up @@ -1022,6 +1021,8 @@ bool AArch64LegalizerInfo::legalizeCustom(LegalizerHelper &Helper,
return legalizeMemOps(MI, Helper);
case TargetOpcode::G_FCOPYSIGN:
return legalizeFCopySign(MI, Helper);
case TargetOpcode::G_EXTRACT_VECTOR_ELT:
return legalizeExtractVectorElt(MI, MRI, Helper);
}

llvm_unreachable("expected switch to return");
Expand Down Expand Up @@ -1801,3 +1802,14 @@ bool AArch64LegalizerInfo::legalizeFCopySign(MachineInstr &MI,
MI.eraseFromParent();
return true;
}

bool AArch64LegalizerInfo::legalizeExtractVectorElt(
MachineInstr &MI, MachineRegisterInfo &MRI, LegalizerHelper &Helper) const {
assert(MI.getOpcode() == TargetOpcode::G_EXTRACT_VECTOR_ELT);
auto VRegAndVal =
getIConstantVRegValWithLookThrough(MI.getOperand(2).getReg(), MRI);
if (VRegAndVal)
return true;
return Helper.lowerExtractInsertVectorElt(MI) !=
LegalizerHelper::LegalizeResult::UnableToLegalize;
}
2 changes: 2 additions & 0 deletions llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class AArch64LegalizerInfo : public LegalizerInfo {
bool legalizeCTTZ(MachineInstr &MI, LegalizerHelper &Helper) const;
bool legalizeMemOps(MachineInstr &MI, LegalizerHelper &Helper) const;
bool legalizeFCopySign(MachineInstr &MI, LegalizerHelper &Helper) const;
bool legalizeExtractVectorElt(MachineInstr &MI, MachineRegisterInfo &MRI,
LegalizerHelper &Helper) const;
const AArch64Subtarget *ST;
};
} // End llvm namespace.
Expand Down
Loading

0 comments on commit a15144f

Please sign in to comment.