Skip to content

Commit a122eee

Browse files
committed
[mlir][arith] Support bitcast with index type
Use kInternalStorageBitWidth as the bit width of index type.
1 parent 45d83ae commit a122eee

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
@@ -1747,7 +1747,18 @@ bool arith::BitcastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
17471747
if (!srcType || !dstType)
17481748
return false;
17491749

1750-
return srcType.getIntOrFloatBitWidth() == dstType.getIntOrFloatBitWidth();
1750+
unsigned srcWidth, dstWidth;
1751+
if (auto indexTy = dyn_cast<IndexType>(srcType))
1752+
srcWidth = IndexType::kInternalStorageBitWidth;
1753+
else
1754+
srcWidth = srcType.getIntOrFloatBitWidth();
1755+
1756+
if (auto indexTy = dyn_cast<IndexType>(dstType))
1757+
dstWidth = IndexType::kInternalStorageBitWidth;
1758+
else
1759+
dstWidth = dstType.getIntOrFloatBitWidth();
1760+
1761+
return srcWidth == dstWidth;
17511762
}
17521763

17531764
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)