Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dialects: (vector) add pure trait to vector.broadcast and vector.fma #3094

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/filecheck/dialects/vector/vector_pure_ops.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: xdsl-opt %s --verify-diagnostics -p cse | filecheck %s

%m0, %i0 = "test.op"() : () -> (memref<4x4xindex>, index)
%load = "vector.load"(%m0, %i0, %i0) : (memref<4x4xindex>, index, index) -> vector<2xindex>
"vector.store"(%load, %m0, %i0, %i0) : (vector<2xindex>, memref<4x4xindex>, index, index) -> ()
%broadcast = "vector.broadcast"(%i0) : (index) -> vector<1xindex>
%fma = "vector.fma"(%load, %load, %load) : (vector<2xindex>, vector<2xindex>, vector<2xindex>) -> vector<2xindex>

/// Check that unused results from vector.broadcast and vector.fma are eliminated
// CHECK: %m0, %i0 = "test.op"() : () -> (memref<4x4xindex>, index)
// CHECK-NEXT: %load = "vector.load"(%m0, %i0, %i0) : (memref<4x4xindex>, index, index) -> vector<2xindex>
// CHECK-NEXT: "vector.store"(%load, %m0, %i0, %i0) : (vector<2xindex>, memref<4x4xindex>, index, index) -> ()
3 changes: 3 additions & 0 deletions xdsl/dialects/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
result_def,
var_operand_def,
)
from xdsl.traits import Pure
from xdsl.utils.exceptions import VerifyException
from xdsl.utils.hints import assert_isa, isa

Expand Down Expand Up @@ -89,6 +90,7 @@ class Broadcast(IRDLOperation):
name = "vector.broadcast"
source: Operand = operand_def(AnyAttr())
vector: OpResult = result_def(VectorType)
traits = frozenset((Pure(),))

def verify_(self):
assert isa(self.vector.type, VectorType[Attribute])
Expand All @@ -113,6 +115,7 @@ class FMA(IRDLOperation):
rhs: Operand = operand_def(VectorType)
acc: Operand = operand_def(VectorType)
res: OpResult = result_def(VectorType)
traits = frozenset((Pure(),))

def verify_(self):
assert isa(self.lhs.type, VectorType[Attribute])
Expand Down
Loading