Skip to content

Commit 4d7c7dd

Browse files
committed
[mlir][arith] Support bitcast with index type
Use kInternalStorageBitWidth as the bit width of index type.
1 parent 0c68155 commit 4d7c7dd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

mlir/lib/Dialect/Arith/IR/ArithOps.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,18 @@ bool arith::BitcastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
17231723
if (!srcType || !dstType)
17241724
return false;
17251725

1726-
return srcType.getIntOrFloatBitWidth() == dstType.getIntOrFloatBitWidth();
1726+
unsigned srcWidth, dstWidth;
1727+
if (auto indexTy = dyn_cast<IndexType>(srcType))
1728+
srcWidth = IndexType::kInternalStorageBitWidth;
1729+
else
1730+
srcWidth = srcType.getIntOrFloatBitWidth();
1731+
1732+
if (auto indexTy = dyn_cast<IndexType>(dstType))
1733+
dstWidth = IndexType::kInternalStorageBitWidth;
1734+
else
1735+
dstWidth = dstType.getIntOrFloatBitWidth();
1736+
1737+
return srcWidth == dstWidth;
17271738
}
17281739

17291740
OpFoldResult arith::BitcastOp::fold(FoldAdaptor adaptor) {

mlir/test/Dialect/Arith/ops.mlir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,12 @@ func.func @test_bitcast_scalable_vector1(%arg0 : vector<[8]xf32>) -> vector<[8]x
954954
return %0 : vector<[8]xi32>
955955
}
956956

957+
// CHECK-LABEL: test_bitcast_index
958+
func.func @test_bitcast_index(%arg0 : i64) -> index {
959+
%0 = arith.bitcast %arg0 : i64 to index
960+
return %0 : index
961+
}
962+
957963
// CHECK-LABEL: test_cmpi
958964
func.func @test_cmpi(%arg0 : i64, %arg1 : i64) -> i1 {
959965
%0 = arith.cmpi ne, %arg0, %arg1 : i64

0 commit comments

Comments
 (0)