forked from OSchip/llvm-project
AMDGPU/GlobalISel: Rework legalization for extract/insert vector elt
Use G_MERGE_VALUES and G_UNMERGE_VALUES on vector elements instead of G_EXTRACT and G_INSERT when doing custom legalization for G_EXTRACT_VECTOR_ELT and G_INSERT_VECTOR_ELT. With this approach legalization artifact combiner gets direct access to all vector elements. Differential Revision: https://reviews.llvm.org/D116115
This commit is contained in:
parent
003ac239d8
commit
d9d2516aaf
|
@ -2213,10 +2213,12 @@ bool AMDGPULegalizerInfo::legalizeExtractVectorElt(
|
||||||
LLT EltTy = VecTy.getElementType();
|
LLT EltTy = VecTy.getElementType();
|
||||||
assert(EltTy == MRI.getType(Dst));
|
assert(EltTy == MRI.getType(Dst));
|
||||||
|
|
||||||
if (IdxVal < VecTy.getNumElements())
|
if (IdxVal < VecTy.getNumElements()) {
|
||||||
B.buildExtract(Dst, Vec, IdxVal * EltTy.getSizeInBits());
|
auto Unmerge = B.buildUnmerge(EltTy, Vec);
|
||||||
else
|
B.buildCopy(Dst, Unmerge.getReg(IdxVal));
|
||||||
|
} else {
|
||||||
B.buildUndef(Dst);
|
B.buildUndef(Dst);
|
||||||
|
}
|
||||||
|
|
||||||
MI.eraseFromParent();
|
MI.eraseFromParent();
|
||||||
return true;
|
return true;
|
||||||
|
@ -2246,10 +2248,18 @@ bool AMDGPULegalizerInfo::legalizeInsertVectorElt(
|
||||||
LLT EltTy = VecTy.getElementType();
|
LLT EltTy = VecTy.getElementType();
|
||||||
assert(EltTy == MRI.getType(Ins));
|
assert(EltTy == MRI.getType(Ins));
|
||||||
|
|
||||||
if (IdxVal < VecTy.getNumElements())
|
unsigned NumElts = VecTy.getNumElements();
|
||||||
B.buildInsert(Dst, Vec, Ins, IdxVal * EltTy.getSizeInBits());
|
if (IdxVal < NumElts) {
|
||||||
else
|
SmallVector<Register, 8> SrcRegs;
|
||||||
|
for (unsigned i = 0; i < NumElts; ++i)
|
||||||
|
SrcRegs.push_back(MRI.createGenericVirtualRegister(EltTy));
|
||||||
|
B.buildUnmerge(SrcRegs, Vec);
|
||||||
|
|
||||||
|
SrcRegs[IdxVal] = MI.getOperand(2).getReg();
|
||||||
|
B.buildMerge(Dst, SrcRegs);
|
||||||
|
} else {
|
||||||
B.buildUndef(Dst);
|
B.buildUndef(Dst);
|
||||||
|
}
|
||||||
|
|
||||||
MI.eraseFromParent();
|
MI.eraseFromParent();
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue