@@ -4044,6 +4044,43 @@ def CIR_ExpectOp : CIR_Op<"expect", [
40444044 }];
40454045}
40464046
4047+ //===----------------------------------------------------------------------===//
4048+ // PtrDiffOp
4049+ //===----------------------------------------------------------------------===//
4050+
4051+ def CIR_PtrDiffOp : CIR_Op<"ptr_diff", [Pure, SameTypeOperands]> {
4052+ let summary = "Pointer subtraction arithmetic";
4053+ let description = [{
4054+ The cir.ptr_diff operation computes the difference between two pointers that
4055+ have the same element type.
4056+
4057+ The result reflects the ABI-defined size of the pointed-to type. For example,
4058+ subtracting two !cir.ptr<!u64i> values may yield 1, representing an 8-byte
4059+ difference. In contrast, for pointers to void or function types, a result of
4060+ 8 corresponds to an 8-byte difference.
4061+
4062+ For pointers to types whose size are not aligned with the target data
4063+ layout, the size is generally rounded to the next power of 2 bits. For
4064+ example, subtracting two !cir.ptr<!s24i> values for the _BitInt(24) type may
4065+ yield 1, representing a 4-byte difference (as opposed to a 3-byte
4066+ difference).
4067+
4068+ Example:
4069+
4070+ ```mlir
4071+ %7 = cir.ptr_diff %0, %1 : !cir.ptr<!u64i> -> !u64i
4072+ ```
4073+ }];
4074+
4075+ let arguments = (ins CIR_PointerType:$lhs, CIR_PointerType:$rhs);
4076+ let results = (outs CIR_AnyFundamentalIntType:$result);
4077+
4078+ let assemblyFormat = [{
4079+ $lhs `,` $rhs `:` qualified(type($lhs)) `->` qualified(type($result))
4080+ attr-dict
4081+ }];
4082+ }
4083+
40474084//===----------------------------------------------------------------------===//
40484085// Floating Point Ops
40494086//===----------------------------------------------------------------------===//
0 commit comments