diff --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp --- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp +++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp @@ -3104,11 +3104,15 @@ IndexCastOpAdaptor transformed(operands); auto targetType = - typeConverter->convertType(indexCastOp.getResult().getType()) + typeConverter->convertType(indexCastOp.getResult().getType()); + auto targetElementType = + typeConverter + ->convertType(getElementTypeOrSelf(indexCastOp.getResult())) .cast(); - auto sourceType = transformed.in().getType().cast(); - unsigned targetBits = targetType.getWidth(); - unsigned sourceBits = sourceType.getWidth(); + auto sourceElementType = + getElementTypeOrSelf(transformed.in()).cast(); + unsigned targetBits = targetElementType.getWidth(); + unsigned sourceBits = sourceElementType.getWidth(); if (targetBits == sourceBits) rewriter.replaceOp(indexCastOp, transformed.in()); diff --git a/mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir b/mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir --- a/mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir +++ b/mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir @@ -520,6 +520,15 @@ return } +// CHECK-LABEL: @vector_index_cast +func @vector_index_cast(%arg0: vector<2xindex>, %arg1: vector<2xi1>) { +// CHECK-NEXT: = llvm.trunc %{{.*}} : vector<2xi{{.*}}> to vector<2xi1> + %0 = index_cast %arg0: vector<2xindex> to vector<2xi1> +// CHECK-NEXT: = llvm.sext %{{.*}} : vector<2xi1> to vector<2xi{{.*}}> + %1 = index_cast %arg1: vector<2xi1> to vector<2xindex> + return +} + // Checking conversion of signed integer types to floating point. // CHECK-LABEL: @sitofp func @sitofp(%arg0 : i32, %arg1 : i64) {