Skip to content

Commit

Permalink
Add two examples
Browse files Browse the repository at this point in the history
  • Loading branch information
math-fehr committed May 16, 2024
1 parent 0390c9e commit 15f0b63
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/filecheck/pdl_to_irdl_check/add_commute.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pdl.pattern @AddCommute : benefit(0) {
%t = pdl.type
%x = pdl.operand : %t
%y = pdl.operand : %t
%op = pdl.operation "arith.addi"(%x, %y : !pdl.value, !pdl.value) -> (%t : !pdl.type)
pdl.rewrite %op {
%new_op = pdl.operation "arith.addi"(%y, %x : !pdl.value, !pdl.value) -> (%t : !pdl.type)
pdl.replace %op with %new_op
}
}
78 changes: 78 additions & 0 deletions tests/filecheck/pdl_to_irdl_check/mulsi_extended_bug.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
irdl.dialect @builtin {
irdl.type @index

irdl.type @integer_type {
%bitwidth = irdl.base "#int"
irdl.parameters(%bitwidth)
}

irdl.attribute @integer_attr {
%index = irdl.base @index
%integer = irdl.base @integer_type
%t = irdl.any_of(%index, %integer)
%value = irdl.any
irdl.parameters(%value, %t)
}
}

irdl.dialect @arith {
irdl.operation @constant {
// %value = irdl.base @builtin::@integer_attr
// irdl.attributes { "value" = %value}
%index = irdl.base @builtin::@index
%integer = irdl.base @builtin::@integer_type
%t = irdl.any_of(%index, %integer)
irdl.results(%t)
}

irdl.operation @mulsi_extended {
%index = irdl.base @builtin::@index
%integer = irdl.base @builtin::@integer_type
%t = irdl.any_of(%index, %integer)
irdl.operands(%t, %t)
irdl.results(%t, %t)
}

irdl.operation @cmpi {
%index = irdl.base @builtin::@index
%integer = irdl.base @builtin::@integer_type
%t = irdl.any_of(%index, %integer)
%i1 = irdl.is i1
irdl.operands(%t, %t)
// irdl.attributes { "predicate" = ... }
irdl.results(%i1)
}

irdl.operation @extsi {
%integer1 = irdl.base @builtin::@integer_type
%integer2 = irdl.base @builtin::@integer_type
irdl.operands(%integer1)
irdl.results(%integer2)
}
}

pdl.pattern @MulSIExtendedRHSOne : benefit(0) {
%t = pdl.type : index
%x = pdl.operand : %t
%one = pdl.attribute : %t
pdl.apply_native_constraint "is_one"(%one : !pdl.attribute)
%one_op = pdl.operation "arith.constant" {"value" = %one} -> (%t : !pdl.type)
%one_val = pdl.result 0 of %one_op

%root = pdl.operation "arith.mulsi_extended"(%x, %one_val : !pdl.value, !pdl.value) -> (%t, %t : !pdl.type, !pdl.type)
pdl.rewrite %root {
%zero = pdl.attribute = 0 : index
%zero_op = pdl.operation "arith.constant" {"value" = %zero} -> (%t : !pdl.type)
%zero_val = pdl.result 0 of %zero_op

%two = pdl.attribute = 2 : index
%i1 = pdl.type : i1
%cmpi_op = pdl.operation "arith.cmpi"(%x, %zero_val : !pdl.value, !pdl.value) {"predicate" = %two} -> (%i1 : !pdl.type)
%cmpi_val = pdl.result 0 of %cmpi_op

%extsi_op = pdl.operation "arith.extsi"(%cmpi_val : !pdl.value) -> (%t : !pdl.type)
%extsi_val = pdl.result 0 of %extsi_op

pdl.replace %root with (%x, %extsi_val : !pdl.value, !pdl.value)
}
}

0 comments on commit 15f0b63

Please sign in to comment.