[llvm] [AArch64][GlobalISel] Legalize Insert vector element (PR #81453)

David Green via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 1 09:53:31 PDT 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:

SelectionDAGBuilder will extend the types as the nodes get constructed in https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp#L3963.
It can be seen in https://godbolt.org/z/eWe1hvjG5.

https://github.com/llvm/llvm-project/pull/81453


More information about the llvm-commits mailing list