blob: 6989eff5235bd49a6463f08b5c9ed82dcf3bcbb3 [file] [edit]
// RUN: mlir-opt -pass-pipeline="builtin.module(func.func(convert-arith-to-llvm{index-bitwidth=32}))" %s | FileCheck %s --check-prefix=CHECK32
// RUN: mlir-opt -pass-pipeline="builtin.module(func.func(convert-arith-to-llvm{index-bitwidth=64}))" %s | FileCheck %s --check-prefix=CHECK64
// RUN: mlir-opt -pass-pipeline="builtin.module(func.func(convert-arith-to-llvm{index-bitwidth=128}))" %s | FileCheck %s --check-prefix=CHECK128
// An `index` constant is retyped to the converted index type, which is signless
// but holds signed values. Narrowing therefore truncates and widening
// sign-extends.
// CHECK32-LABEL: @scalar_index_constant
// CHECK32: llvm.mlir.constant(-1 : i32) : i32
// CHECK32: llvm.mlir.constant(0 : i32) : i32
// CHECK64-LABEL: @scalar_index_constant
// CHECK64: llvm.mlir.constant(-1 : i64) : i64
// CHECK64: llvm.mlir.constant(4294967296 : i64) : i64
// CHECK128-LABEL: @scalar_index_constant
// CHECK128: llvm.mlir.constant(-1 : i128) : i128
// CHECK128: llvm.mlir.constant(4294967296 : i128) : i128
func.func @scalar_index_constant() -> (index, index) {
%0 = arith.constant -1 : index
%1 = arith.constant 4294967296 : index
return %0, %1 : index, index
}
// CHECK32-LABEL: @dense_index_constant
// CHECK32: llvm.mlir.constant(dense<[-1, 0]> : vector<2xi32>) : vector<2xi32>
// CHECK64-LABEL: @dense_index_constant
// CHECK64: llvm.mlir.constant(dense<[-1, 4294967296]> : vector<2xi64>) : vector<2xi64>
// CHECK128-LABEL: @dense_index_constant
// CHECK128: llvm.mlir.constant(dense<[-1, 4294967296]> : vector<2xi128>) : vector<2xi128>
func.func @dense_index_constant() -> vector<2xindex> {
%0 = arith.constant dense<[-1, 4294967296]> : vector<2xindex>
return %0 : vector<2xindex>
}
// CHECK32-LABEL: @sparse_index_constant
// CHECK32: llvm.mlir.constant(sparse<0, -1> : vector<4xi32>) : vector<4xi32>
// CHECK64-LABEL: @sparse_index_constant
// CHECK64: llvm.mlir.constant(sparse<0, -1> : vector<4xi64>) : vector<4xi64>
// CHECK128-LABEL: @sparse_index_constant
// CHECK128: llvm.mlir.constant(sparse<0, -1> : vector<4xi128>) : vector<4xi128>
func.func @sparse_index_constant() -> vector<4xindex> {
%0 = arith.constant sparse<[[0]], [-1]> : vector<4xindex>
return %0 : vector<4xindex>
}
// A resource-backed elements attribute is only reinterpreted, so it can be
// retyped exactly when the converted index type has the same width as the
// storage `index` uses in a blob. Otherwise the lowering fails.
// CHECK32-LABEL: @resource_index_constant
// CHECK32: arith.constant dense_resource<index_blob> : vector<2xindex>
// CHECK64-LABEL: @resource_index_constant
// CHECK64: llvm.mlir.constant(dense_resource<index_blob> : vector<2xi64>) : vector<2xi64>
// CHECK128-LABEL: @resource_index_constant
// CHECK128: arith.constant dense_resource<index_blob> : vector<2xindex>
func.func @resource_index_constant() -> vector<2xindex> {
%0 = arith.constant dense_resource<index_blob> : vector<2xindex>
return %0 : vector<2xindex>
}
// The sum's type must be converted to the configured index width when building
// the LLVM struct that holds the sum and overflow indicator.
// CHECK32-LABEL: @addui_extended_index
// CHECK32: "llvm.intr.uadd.with.overflow"{{.*}} : (i32, i32) -> !llvm.struct<(i32, i1)>
// CHECK64-LABEL: @addui_extended_index
// CHECK64: "llvm.intr.uadd.with.overflow"{{.*}} : (i64, i64) -> !llvm.struct<(i64, i1)>
// CHECK128-LABEL: @addui_extended_index
// CHECK128: "llvm.intr.uadd.with.overflow"{{.*}} : (i128, i128) -> !llvm.struct<(i128, i1)>
func.func @addui_extended_index(%a: index, %b: index) -> (index, i1) {
%sum, %overflow = arith.addui_extended %a, %b : index, i1
return %sum, %overflow : index, i1
}
{-#
dialect_resources: {
builtin: {
index_blob: "0x0800000001000000000000000200000000000000"
}
}
#-}