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 @@ -172,6 +172,9 @@ Location loc) -> Optional { if (inputs.size() != 1) return llvm::None; + // Dialect cast does not support index type. + if (resultType == builder.getIndexType()) + return inputs[0]; // FIXME: These should check LLVM::DialectCastOp can actually be constructed // from the input and result. return builder.create(loc, resultType, inputs[0]) @@ -182,6 +185,9 @@ Location loc) -> Optional { if (inputs.size() != 1) return llvm::None; + // Dialect cast does not support index type. + if (resultType == builder.getIndexType()) + return inputs[0]; // FIXME: These should check LLVM::DialectCastOp can actually be constructed // from the input and result. return builder.create(loc, resultType, inputs[0]) diff --git a/mlir/test/Conversion/StandardToLLVM/dialect-cast.mlir b/mlir/test/Conversion/StandardToLLVM/dialect-cast.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/Conversion/StandardToLLVM/dialect-cast.mlir @@ -0,0 +1,13 @@ +// RUN: mlir-opt %s --convert-std-and-scf-to-llvm --split-input-file -verify-diagnostics | FileCheck %s + +// CHECK-LABEL: @no_index_cast +func @no_index_cast() { + // CHECK: not mlir.llvm.cast + %c0 = constant 0 : index + %c1 = constant 1 : index + scf.for %i = %c0 to %c1 step %c1 iter_args(%aggr = %c0) { + %c123 = constant 123 : index + scf.yield %c123 : index + } +} +