-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir][arith][tensor] Disable index type for bitcast #121455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-flang-fir-hlfir @llvm/pr-subscribers-mlir-arith Author: Jianjian Guan (jacquesguan) ChangesUse kInternalStorageBitWidth as the bit width of index type. Full diff: https://github.com/llvm/llvm-project/pull/121455.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index d8b314a3fa43c0..6c4aee3aad94fe 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -1723,7 +1723,18 @@ bool arith::BitcastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
if (!srcType || !dstType)
return false;
- return srcType.getIntOrFloatBitWidth() == dstType.getIntOrFloatBitWidth();
+ unsigned srcWidth, dstWidth;
+ if (auto indexTy = dyn_cast<IndexType>(srcType))
+ srcWidth = IndexType::kInternalStorageBitWidth;
+ else
+ srcWidth = srcType.getIntOrFloatBitWidth();
+
+ if (auto indexTy = dyn_cast<IndexType>(dstType))
+ dstWidth = IndexType::kInternalStorageBitWidth;
+ else
+ dstWidth = dstType.getIntOrFloatBitWidth();
+
+ return srcWidth == dstWidth;
}
OpFoldResult arith::BitcastOp::fold(FoldAdaptor adaptor) {
diff --git a/mlir/test/Dialect/Arith/ops.mlir b/mlir/test/Dialect/Arith/ops.mlir
index f684e02344a517..46cb1993a3b789 100644
--- a/mlir/test/Dialect/Arith/ops.mlir
+++ b/mlir/test/Dialect/Arith/ops.mlir
@@ -954,6 +954,12 @@ func.func @test_bitcast_scalable_vector1(%arg0 : vector<[8]xf32>) -> vector<[8]x
return %0 : vector<[8]xi32>
}
+// CHECK-LABEL: test_bitcast_index
+func.func @test_bitcast_index(%arg0 : i64) -> index {
+ %0 = arith.bitcast %arg0 : i64 to index
+ return %0 : index
+}
+
// CHECK-LABEL: test_cmpi
func.func @test_cmpi(%arg0 : i64, %arg1 : i64) -> i1 {
%0 = arith.cmpi ne, %arg0, %arg1 : i64
|
@llvm/pr-subscribers-mlir Author: Jianjian Guan (jacquesguan) ChangesUse kInternalStorageBitWidth as the bit width of index type. Full diff: https://github.com/llvm/llvm-project/pull/121455.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index d8b314a3fa43c0..6c4aee3aad94fe 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -1723,7 +1723,18 @@ bool arith::BitcastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
if (!srcType || !dstType)
return false;
- return srcType.getIntOrFloatBitWidth() == dstType.getIntOrFloatBitWidth();
+ unsigned srcWidth, dstWidth;
+ if (auto indexTy = dyn_cast<IndexType>(srcType))
+ srcWidth = IndexType::kInternalStorageBitWidth;
+ else
+ srcWidth = srcType.getIntOrFloatBitWidth();
+
+ if (auto indexTy = dyn_cast<IndexType>(dstType))
+ dstWidth = IndexType::kInternalStorageBitWidth;
+ else
+ dstWidth = dstType.getIntOrFloatBitWidth();
+
+ return srcWidth == dstWidth;
}
OpFoldResult arith::BitcastOp::fold(FoldAdaptor adaptor) {
diff --git a/mlir/test/Dialect/Arith/ops.mlir b/mlir/test/Dialect/Arith/ops.mlir
index f684e02344a517..46cb1993a3b789 100644
--- a/mlir/test/Dialect/Arith/ops.mlir
+++ b/mlir/test/Dialect/Arith/ops.mlir
@@ -954,6 +954,12 @@ func.func @test_bitcast_scalable_vector1(%arg0 : vector<[8]xf32>) -> vector<[8]x
return %0 : vector<[8]xi32>
}
+// CHECK-LABEL: test_bitcast_index
+func.func @test_bitcast_index(%arg0 : i64) -> index {
+ %0 = arith.bitcast %arg0 : i64 to index
+ return %0 : index
+}
+
// CHECK-LABEL: test_cmpi
func.func @test_cmpi(%arg0 : i64, %arg1 : i64) -> i1 {
%0 = arith.cmpi ne, %arg0, %arg1 : i64
|
Thanks for your work, and I think we should fix
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think arith.bitcast
should not be used with index type. The bitwidth is unknown, so a bitcast does not make sense. Can we improve the verifier and reject such ops? Note, there is a special index_cast
op to convert from/to index type.
+1. A value of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think the internal storage really represents the actual bitwidth used. That only becomes apparent later on, for example when lowering to LLVM this is set as a field in the data layout used to lower index types.
EDIT: +1 to what was said above as well. Should disallow index types in bitcast operations.
+1 |
Thanks for all comments, I change this PR to disable index type for arith.bitcast and tensor.bitcast. |
And I think it's better to change the constraint of llvm-project/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td Lines 78 to 79 in aa0f334
|
Done, also add signed and unsigned integer. |
@@ -908,6 +908,11 @@ def BoolLike : TypeOrContainer<I1, "bool-like">; | |||
|
|||
def BoolLikeOfAnyRank : TypeOrContainerOfAnyRank<I1, "bool-like">; | |||
|
|||
// Type constraint for signless-integer-like types: signless integers, | |||
// vectors of signless integers or tensors of signless integers. | |||
def SignlessInteger : TypeOrValueSemanticsContainer< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit confusing because there is also SignlessIntegerLike
below.
I would change it as follows:
- Rename
SignlessIntegerLike
toSignlessIntegerOrIndexLike
. - Rename
SignlessIntegerLikeOfAnyRank
toSignlessIntegerOrIndexLikeOfAnyRank
- Call this new definition
SignlessIntegerLike
instead ofSignlessInteger
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for comment, I rename these constraints.
230be88
to
91bf8e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is LGTM now, and please resolve the tests failure.
Use kInternalStorageBitWidth as the bit width of index type.
91bf8e2
to
5767f51
Compare
Use kInternalStorageBitWidth as the bit width of index type. Fixes #121397.