[clang] [clang][clangir] add vpaddl and vpaddlq support (PR #191845)

Andrzej WarzyƄski via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 16 04:11:53 PDT 2026


================
@@ -196,6 +196,40 @@ static mlir::Value emitNeonCall(CIRGenModule &cgm, CIRGenBuilderTy &builder,
       isConstrainedFPIntrinsic, shift, rightshift);
 }
 
+static cir::VectorType getVPaddlInputVectorType(cir::VectorType resType,
+                                                bool usgn) {
+  mlir::Type elemTy = resType.getElementType();
+  uint64_t lanes = resType.getSize();
+  auto intTy = mlir::dyn_cast<cir::IntType>(elemTy);
+  if (!intTy) {
+    llvm_unreachable("vpaddl result type must be an integer vector");
+  }
+  unsigned resWidth = intTy.getWidth();
+  assert((resWidth == 16 || resWidth == 32 || resWidth == 64) &&
+         "unexpected vpaddl result element width");
+
+  unsigned argWidth = resWidth / 2;
+  unsigned argLanes = lanes * 2;
+  mlir::Type argElemTy =
+      cir::IntType::get(resType.getContext(), argWidth, /* is_signed*/ !usgn);
+  cir::VectorType result = cir::VectorType::get(argElemTy, argLanes);
+  return result;
+}
+
+static mlir::Value emitNeonVPaddlCall(CIRGenFunction &cgf,
+                                      llvm::SmallVectorImpl<mlir::Value> &args,
+                                      cir::VectorType vTy, mlir::Location loc,
+                                      unsigned uIntrID, unsigned sIntrID,
+                                      bool usgn) {
+  llvm::StringRef llvmIntrName = getLLVMIntrNameNoPrefix(
+      static_cast<llvm::Intrinsic::ID>(usgn ? uIntrID : sIntrID));
+  args[0] = cgf.getBuilder().createBitcast(args[0],
+                                           getVPaddlInputVectorType(vTy, usgn));
+  return emitNeonCall(cgf.getCIRGenModule(), cgf.getBuilder(),
+                      /*argTypes=*/{args[0].getType()}, args, llvmIntrName,
+                      /*funcResTy=*/vTy, loc);
+}
----------------
banach-space wrote:

I would prefer to avoid this extra indirection - the code becomes tricky to follow and diverges from https://github.com/llvm/llvm-project/blob/7b4c9bb2069536e0df18597795b858e18a1cbaaf/clang/lib/CodeGen/TargetBuiltins/ARM.cpp.

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


More information about the cfe-commits mailing list