[Mlir-commits] [mlir] [mlir][ptr] Add `ptr.ptr_diff` operation (PR #157354)
Fabian Mora
llvmlistbot at llvm.org
Mon Sep 15 06:03:58 PDT 2025
================
@@ -415,6 +415,63 @@ def Ptr_PtrAddOp : Pointer_Op<"ptr_add", [
}];
}
+//===----------------------------------------------------------------------===//
+// PtrDiffOp
+//===----------------------------------------------------------------------===//
+
+def Ptr_PtrDiffOp : Pointer_Op<"ptr_diff", [
+ Pure, AllTypesMatch<["lhs", "rhs"]>, SameOperandsAndResultShape
+ ]> {
+ let summary = "Pointer difference operation";
+ let description = [{
+ The `ptr_diff` operation computes the difference between two pointers,
+ returning an integer or index value representing the number of bytes
+ between them. This difference is always computed using signed arithmetic.
----------------
fabianmcg wrote:
Negative pointers no, but take: (ptr + 16) - (ptr + 32), the result will be negative.
I took as rationale the existence of `ptrdiff_t` in C https://en.cppreference.com/w/c/types/ptrdiff_t.html
I'll clarify the comment.
https://github.com/llvm/llvm-project/pull/157354
More information about the Mlir-commits
mailing list