[Mlir-commits] [mlir] [mlir][ptr] Add `ptr.ptr_diff` operation (PR #157354)
Fabian Mora
llvmlistbot at llvm.org
Mon Sep 15 09:33:41 PDT 2025
================
@@ -391,6 +392,39 @@ LogicalResult PtrAddOp::inferReturnTypes(
return success();
}
+//===----------------------------------------------------------------------===//
+// PtrDiffOp
+//===----------------------------------------------------------------------===//
+
+LogicalResult PtrDiffOp::verify() {
+ // If the operands are not shaped early exit.
+ if (!isa<ShapedType>(getLhs().getType()))
+ return success();
+
+ // Just check the container type matches, `SameOperandsAndResultShape` handles
+ // the actual shape.
+ if (getResult().getType().getTypeID() != getLhs().getType().getTypeID()) {
+ return emitError() << "expected the result to have the same container "
+ "type as the operands when operands are shaped";
+ }
+
+ return success();
+}
+
+ptr::PtrType PtrDiffOp::getPtrType() {
+ Type lhsType = getLhs().getType();
+ if (auto shapedType = dyn_cast<ShapedType>(lhsType))
+ return cast<ptr::PtrType>(shapedType.getElementType());
+ return cast<ptr::PtrType>(lhsType);
+}
+
+Type PtrDiffOp::getIntType() {
+ Type resultType = getResult().getType();
+ if (auto shapedType = dyn_cast<ShapedType>(resultType))
+ return shapedType.getElementType();
+ return resultType;
+}
+
----------------
fabianmcg wrote:
Sure, in general I need to improve the folders and canonicalizers of the entire dialect, so how about a new PR for that?
https://github.com/llvm/llvm-project/pull/157354
More information about the Mlir-commits
mailing list