Index: llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h =================================================================== --- llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h +++ llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h @@ -357,6 +357,14 @@ /// Keep the same scalar or element type as the given type. LegalizeMutation changeElementTo(unsigned TypeIdx, LLT Ty); +/// Keep the same scalar or element type as \p TypeIdx, but take the number of +/// elements from \p FromTypeIdx. +LegalizeMutation changeElementCountTo(unsigned TypeIdx, unsigned FromTypeIdx); + +/// Keep the same scalar or element type as \p TypeIdx, but take the number of +/// elements from \p Ty. +LegalizeMutation changeElementCountTo(unsigned TypeIdx, LLT Ty); + /// Change the scalar size or element size to have the same scalar size as type /// index \p FromIndex. Unlike changeElementTo, this discards pointer types and /// only changes the size. Index: llvm/lib/CodeGen/GlobalISel/LegalizeMutations.cpp =================================================================== --- llvm/lib/CodeGen/GlobalISel/LegalizeMutations.cpp +++ llvm/lib/CodeGen/GlobalISel/LegalizeMutations.cpp @@ -43,6 +43,25 @@ }; } +LegalizeMutation LegalizeMutations::changeElementCountTo(unsigned TypeIdx, + unsigned FromTypeIdx) { + return [=](const LegalityQuery &Query) { + const LLT OldTy = Query.Types[TypeIdx]; + const LLT NewTy = Query.Types[FromTypeIdx]; + return std::make_pair(TypeIdx, + OldTy.changeElementCount(NewTy.getElementCount())); + }; +} + +LegalizeMutation LegalizeMutations::changeElementCountTo(unsigned TypeIdx, + LLT NewEltTy) { + return [=](const LegalityQuery &Query) { + const LLT OldTy = Query.Types[TypeIdx]; + return std::make_pair(TypeIdx, + OldTy.changeElementCount(NewEltTy.getElementCount())); + }; +} + LegalizeMutation LegalizeMutations::changeElementSizeTo(unsigned TypeIdx, unsigned FromTypeIdx) { return [=](const LegalityQuery &Query) {