[llvm-branch-commits] [mlir] [mlir][ptr] Add `gather`, `masked_load`, `masked_store`, and `scatter` ops (PR #156368)
Fabian Mora via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Sep 2 04:35:14 PDT 2025
================
@@ -56,6 +96,58 @@ def Ptr_FromPtrOp : Pointer_Op<"from_ptr", [
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// GatherOp
+//===----------------------------------------------------------------------===//
+
+def Ptr_GatherOp : Pointer_Op<"gather", [
+ DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
+ TypesMatchWith<"result and mask must be compatible", "result", "mask", [{
+ ::llvm::cast<ShapedType>($_self).clone(
+ IntegerType::get($_self.getContext(), 1))
+ }]>,
+ AllTypesMatch<["result", "passthrough"]>,
+ // Check the shapes are compatible and both use the same shaped container
+ // type.
+ AllShapesMatch<["result", "ptrs"]>, AllTypeIDsMatch<["result", "ptrs"]>
+ ]> {
+ let summary = "Gather operation";
+ let description = [{
+ The `gather` operation performs conditional loads from multiple memory
+ locations specified by `ptrs` based on a mask `mask`. Elements of the
+ result corresponding to masked-off lanes are taken from the passthrough
+ operand.
+
+ The mask operand is a shaped type of `i1` elements that must have the same
+ shape as the result type.
+
+ Examples:
+ ```mlir
+ // Gather values from multiple memory locations
+ %result = ptr.gather %ptrs, %mask, %passthrough :
+ vector<4x!ptr.ptr<#ptr.generic_space>> -> vector<4xf32>
+
+ // Gather with alignment
+ %result = ptr.gather %ptrs, %mask, %passthrough alignment = 8 :
+ vector<4x!ptr.ptr<#ptr.generic_space>> -> vector<4xf32>
+ ```
+ }];
+ let arguments = (ins Ptr_Ptr1DType:$ptrs,
+ Ptr_Mask1DType:$mask,
+ Ptr_Any1DType:$passthrough,
+ AlignmentProp:$alignment);
+ let results = (outs Ptr_Any1DType:$result);
+ let assemblyFormat = [{
+ $ptrs `,` $mask `,` $passthrough (`alignment` `=` $alignment^)?
+ attr-dict `:` qualified(type($ptrs)) `->` type($result)
----------------
fabianmcg wrote:
I generally prefer qualified type, but I'll remove.
https://github.com/llvm/llvm-project/pull/156368
More information about the llvm-branch-commits
mailing list