Skip to content

Commit 5032fa8

Browse files
authored
[MLIR][EmitC] Allow ptrdiff_t as result in sub op (llvm#104921)
This explicitly allows the `emitc.ptrdiff_t` type for the result of substrating two pointers and changes the example accordingly.
1 parent 5f77734 commit 5032fa8

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

mlir/include/mlir/Dialect/EmitC/IR/EmitC.td

+1-1
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ def EmitC_SubOp : EmitC_BinaryOp<"sub", [CExpression]> {
924924
%0 = emitc.sub %arg0, %arg1 : (i32, i32) -> i32
925925
%1 = emitc.sub %arg2, %arg3 : (!emitc.ptr<f32>, i32) -> !emitc.ptr<f32>
926926
%2 = emitc.sub %arg4, %arg5 : (!emitc.ptr<i32>, !emitc.ptr<i32>)
927-
-> !emitc.opaque<"ptrdiff_t">
927+
-> !emitc.ptrdiff_t
928928
```
929929
```c++
930930
// Code emitted for the operations above.

mlir/lib/Dialect/EmitC/IR/EmitC.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,9 @@ LogicalResult SubOp::verify() {
808808
"type if lhs is a pointer");
809809

810810
if (isa<emitc::PointerType>(lhsType) && isa<emitc::PointerType>(rhsType) &&
811-
!isa<IntegerType, emitc::OpaqueType>(resultType))
812-
return emitOpError("requires that the result is an integer or of opaque "
813-
"type if lhs and rhs are pointers");
811+
!isa<IntegerType, emitc::PtrDiffTType, emitc::OpaqueType>(resultType))
812+
return emitOpError("requires that the result is an integer, ptrdiff_t or "
813+
"of opaque type if lhs and rhs are pointers");
814814
return success();
815815
}
816816

mlir/test/Dialect/EmitC/invalid_ops.mlir

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func.func @sub_pointer_float(%arg0: !emitc.ptr<f32>, %arg1: f32) {
212212
// -----
213213

214214
func.func @sub_pointer_pointer(%arg0: !emitc.ptr<f32>, %arg1: !emitc.ptr<f32>) {
215-
// expected-error @+1 {{'emitc.sub' op requires that the result is an integer or of opaque type if lhs and rhs are pointers}}
215+
// expected-error @+1 {{'emitc.sub' op requires that the result is an integer, ptrdiff_t or of opaque type if lhs and rhs are pointers}}
216216
%1 = "emitc.sub" (%arg0, %arg1) : (!emitc.ptr<f32>, !emitc.ptr<f32>) -> !emitc.ptr<f32>
217217
return
218218
}

mlir/test/Dialect/EmitC/ops.mlir

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func.func @sub_pointer(%arg0: !emitc.ptr<f32>, %arg1: i32, %arg2: !emitc.opaque<
116116
%2 = "emitc.sub" (%arg0, %arg2) : (!emitc.ptr<f32>, !emitc.opaque<"unsigned int">) -> !emitc.ptr<f32>
117117
%3 = "emitc.sub" (%arg0, %arg3) : (!emitc.ptr<f32>, !emitc.ptr<f32>) -> !emitc.opaque<"ptrdiff_t">
118118
%4 = "emitc.sub" (%arg0, %arg3) : (!emitc.ptr<f32>, !emitc.ptr<f32>) -> i32
119+
%5 = "emitc.sub" (%arg0, %arg3) : (!emitc.ptr<f32>, !emitc.ptr<f32>) -> !emitc.ptrdiff_t
119120
return
120121
}
121122

0 commit comments

Comments
 (0)