[llvm] [AArch64][GlobalISel] Legalize Insert vector element (PR #81453)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 8 07:03:44 PST 2024
================
@@ -2972,7 +2972,22 @@ bool IRTranslator::translateInsertElement(const User &U,
Register Res = getOrCreateVReg(U);
Register Val = getOrCreateVReg(*U.getOperand(0));
Register Elt = getOrCreateVReg(*U.getOperand(1));
- Register Idx = getOrCreateVReg(*U.getOperand(2));
+ const auto &TLI = *MF->getSubtarget().getTargetLowering();
+ unsigned PreferredVecIdxWidth = TLI.getVectorIdxTy(*DL).getSizeInBits();
+ Register Idx;
+ if (auto *CI = dyn_cast<ConstantInt>(U.getOperand(2))) {
+ if (CI->getBitWidth() != PreferredVecIdxWidth) {
+ APInt NewIdx = CI->getValue().zextOrTrunc(PreferredVecIdxWidth);
+ auto *NewIdxCI = ConstantInt::get(CI->getContext(), NewIdx);
----------------
davemgreen wrote:
I would seem beneficial for it to work the same way as SDAG where the idx type to always be getVectorIdxTy(), either before or after legalization. It helps simplify things quite a bit if the rest of the code can rely on the type of the indices.
https://github.com/llvm/llvm-project/pull/81453
More information about the llvm-commits
mailing list