[clang] [CIR] Add SVE support to CIR calling convention lowering (PR #248727)

Madhur Amilkanthwar via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 3 23:19:03 PST 2026


================
@@ -2204,6 +2204,62 @@ mlir::LogicalResult CIRToLLVMCastOpLowering::matchAndRewrite(
     assert(!MissingFeatures::dataMemberType());
 
     mlir::Value llvmSrcVal = adaptor.getSrc();
+    auto srcVecTy = mlir::dyn_cast<cir::VectorType>(castOp.getSrc().getType());
+    auto dstVecTy = mlir::dyn_cast<cir::VectorType>(dstTy);
+    if (srcVecTy && dstVecTy &&
+        srcVecTy.isScalable() != dstVecTy.isScalable()) {
+      auto llvmSrcTy = mlir::cast<mlir::VectorType>(llvmSrcVal.getType());
+      auto llvmDstVecTy = mlir::cast<mlir::VectorType>(llvmDstTy);
+      auto zero = rewriter.getI64IntegerAttr(0);
+
+      if (!srcVecTy.isScalable()) {
+        mlir::Type insertTy = llvmDstVecTy;
+        // Fixed predicates use i8 elements, while their scalable ABI type
+        // uses i1 elements. Insert into a scalable i8 vector and bitcast it.
+        if (llvmDstVecTy.getElementType().isInteger(1) &&
----------------
madhur13490 wrote:

I think this breaks when the predicate's element count isn't a multiple of 8.
For example, with <vscale x 4 x i1> we create <vscale x 1 x i8> and then
bitcast it straight to <vscale x 4 x i1>, but those aren't the same size.
Classic CreateCoercedLoad handles this by bitcasting to the rounded-up i1 type
and then doing a vector.extract. The scalable-to-fixed path below already pads
the same way classic does, so it'd be nice if this direction matched it, or at
least asserted that the count is a multiple of 8.

Also, classic falls back to going through memory if the element types still
don't match after the predicate adjustment. Here we'd emit a vector.insert
with mismatched element types. Maybe add an assert?

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


More information about the cfe-commits mailing list