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

[RTL] Add pattern matching to rtl tests #59

Merged
merged 2 commits into from
Jul 29, 2020
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
26 changes: 13 additions & 13 deletions test/rtl/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@
// CHECK-LABEL: func @test1(%arg0: i3) -> i50 {
func @test1(%arg0: i3) -> i50 {
// CHECK-NEXT: %c42_i12 = rtl.constant(42 : i12) : i12
amaleewilson marked this conversation as resolved.
Show resolved Hide resolved
// CHECK-NEXT: %0 = rtl.add %c42_i12, %c42_i12 : i12
// CHECK-NEXT: %1 = rtl.mul %c42_i12, %0 : i12
// CHECK-NEXT: %[[RES0:.*]] = rtl.add %c42_i12, %c42_i12 : i12
// CHECK-NEXT: %[[RES1:.*]] = rtl.mul %c42_i12, %[[RES0:.*]] : i12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[[RES0:.*]] is a capture expression. To use the captured value as a pattern, you need to use [[RES0]].
Since the test only uses capture expressions, this is equivalent to just use wildcards as in:

// CHECK-NEXT:    %{{.*}} = rtl.mul %c42_i12, %{{.*}} : i12

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good catch I should have noticed that. Thank you!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you expect a number, you can be more specific and use [[RES0:[0-9]+]]. As a question of style, I would probably also include the % to the pattern: [[RES0:%[0-9]+]].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jprotze!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd personally just write .* because it is unambiguous and the pattern is simpler, but we're now so far down the line of personal preference that anything is fine :-)

%a = rtl.constant(42 : i12) : i12
%b = rtl.add %a, %a : i12
%c = rtl.mul %a, %b : i12

// CHECK-NEXT: %2 = rtl.sext %arg0 : (i3) -> i7
// CHECK-NEXT: %3 = rtl.zext %arg0 : (i3) -> i7
// CHECK-NEXT: %[[RES2:.*]] = rtl.sext %arg0 : (i3) -> i7
// CHECK-NEXT: %[[RES3:.*]] = rtl.zext %arg0 : (i3) -> i7
%d = rtl.sext %arg0 : (i3) -> i7
%e = rtl.zext %arg0 : (i3) -> i7

// CHECK-NEXT: %4 = rtl.concat %c42_i12 : (i12) -> i12
// CHECK-NEXT: %[[RES4:.*]] = rtl.concat %[[C42_i12:.*]] : (i12) -> i12
%conc1 = rtl.concat %a : (i12) -> i12

// CHECK-NEXT: %5 = rtl.andr %4 : i12
// CHECK-NEXT: %6 = rtl.orr %4 : i12
// CHECK-NEXT: %7 = rtl.xorr %4 : i12
// CHECK-NEXT: %[[RES5:.*]] = rtl.andr %[[RES4:.*]] : i12
// CHECK-NEXT: %[[RES6:.*]] = rtl.orr %[[RES4:.*]] : i12
// CHECK-NEXT: %[[RES7:.*]] = rtl.xorr %[[RES4:.*]] : i12
%andr1 = rtl.andr %conc1 : i12
%orr1 = rtl.orr %conc1 : i12
%xorr1 = rtl.xorr %conc1 : i12

// CHECK-NEXT: %8 = rtl.concat %4, %0, %1, %2, %3 : (i12, i12, i12, i7, i7) -> i50
// CHECK-NEXT: %[[RES8:.*]] = rtl.concat %[[RES4:.*]], %[[RES0:.*]], %[[RES1:.*]], %[[RES2:.*]], %[[RES3:.*]] : (i12, i12, i12, i7, i7) -> i50
%result = rtl.concat %conc1, %b, %c, %d, %e : (i12, i12, i12, i7, i7) -> i50

// CHECK-NEXT: rtl.extract %8 from 4 : (i50) -> i19
// CHECK-NEXT: %[[RES9:.*]] = rtl.extract [[RES8:.*]] from 4 : (i50) -> i19
%small1 = rtl.extract %result from 4 : (i50) -> i19

// CHECK-NEXT: rtl.extract %8 from 31 : (i50) -> i19
// CHECK-NEXT: %[[RES10:.*]] = rtl.extract [[RES8:.*]] from 31 : (i50) -> i19
%small2 = rtl.extract %result from 31 : (i50) -> i19

// CHECK-NEXT: rtl.add
// CHECK-NEXT: rtl.add %[[RES9:.*]], %[[RES10:.*]] : i19
%add = rtl.add %small1, %small2 : i19

// CHECK-NEXT: = rtl.wire : i4
%w = rtl.wire : i4

// CHECK-NEXT: return %8 : i50
// CHECK-NEXT: return [[RES8:.*]] : i50
return %result : i50
}
// CHECK-NEXT: }
8 changes: 4 additions & 4 deletions test/rtl/bitwise.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

// CHECK-LABEL: func @bitwise(%arg0: i7, %arg1: i7) -> i21 {
func @bitwise(%a: i7, %b: i7) -> i21 {
// CHECK-NEXT: %0 = rtl.xor %arg0 : i7
// CHECK-NEXT: %1 = rtl.or %arg0, %arg1 : i7
// CHECK-NEXT: %2 = rtl.and %arg0, %arg1, %arg0 : i7
// CHECK-NEXT: %[[RES0:.*]] = rtl.xor %arg0 : i7
// CHECK-NEXT: %[[RES1:.*]] = rtl.or %arg0, %arg1 : i7
// CHECK-NEXT: %[[RES2:.*]] = rtl.and %arg0, %arg1, %arg0 : i7
%and1 = rtl.xor %a : i7
%or1 = rtl.or %a, %b : i7
%xor1 = rtl.and %a, %b, %a : i7

// CHECK-NEXT: %[[RESULT:.*]] = rtl.concat %0, %1, %2 : (i7, i7, i7) -> i21
// CHECK-NEXT: %[[RESULT:.*]] = rtl.concat %[[RES0:.*]], %[[RES1:.*]], %[[RES2:.*]] : (i7, i7, i7) -> i21
// CHECK-NEXT: return %[[RESULT]] : i21
%result = rtl.concat %and1, %or1, %xor1 : (i7, i7, i7) -> i21
return %result : i21
Expand Down
22 changes: 11 additions & 11 deletions test/rtl/canonicalization.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func @extract_noop(%arg0: i3) -> i3 {

// CHECK-LABEL: func @extract_cstfold() -> i3 {
// CHECK-NEXT: %c-3_i3 = rtl.constant(-3 : i3)
// CHECK-NEXT: return %c-3_i3
// CHECK-NEXT: return %c-3_i3

func @extract_cstfold() -> i3 {
%c42_i12 = rtl.constant(42 : i12) : i12
Expand Down Expand Up @@ -63,8 +63,8 @@ func @mul_annulment(%arg0: i11, %arg1: i11, %arg2: i11) -> i11 {
// Identities

// CHECK-LABEL: func @and_identity(%arg0: i11, %arg1: i11) -> i11 {
// CHECK-NEXT: %0 = rtl.and %arg0, %arg1
// CHECK-NEXT: return %0
// CHECK-NEXT: %[[RES:.*]] = rtl.and %arg0, %arg1
// CHECK-NEXT: return %[[RES:.*]]

func @and_identity(%arg0: i11, %arg1: i11) -> i11 {
%c-1_i11 = rtl.constant(-1 : i11) : i11
Expand All @@ -73,8 +73,8 @@ func @and_identity(%arg0: i11, %arg1: i11) -> i11 {
}

// CHECK-LABEL: func @or_identity(%arg0: i11, %arg1: i11) -> i11 {
// CHECK-NEXT: %0 = rtl.or %arg0, %arg1
// CHECK-NEXT: return %0
// CHECK-NEXT: %[[RES:.*]] = rtl.or %arg0, %arg1
// CHECK-NEXT: return %[[RES:.*]]

func @or_identity(%arg0: i11, %arg1: i11) -> i11 {
%c0_i11 = rtl.constant(0 : i11) : i11
Expand All @@ -83,8 +83,8 @@ func @or_identity(%arg0: i11, %arg1: i11) -> i11 {
}

// CHECK-LABEL: func @xor_identity(%arg0: i11, %arg1: i11) -> i11 {
// CHECK-NEXT: %0 = rtl.xor %arg1, %arg0
// CHECK-NEXT: return %0
// CHECK-NEXT: %[[RES:.*]] = rtl.xor %arg1, %arg0
// CHECK-NEXT: return %[[RES:.*]]

func @xor_identity(%arg0: i11, %arg1: i11) -> i11 {
%c0_i11 = rtl.constant(0 : i11) : i11
Expand All @@ -93,8 +93,8 @@ func @xor_identity(%arg0: i11, %arg1: i11) -> i11 {
}

// CHECK-LABEL: func @add_identity(%arg0: i11, %arg1: i11) -> i11 {
// CHECK-NEXT: %0 = rtl.add %arg0, %arg1
// CHECK-NEXT: return %0
// CHECK-NEXT: %[[RES:.*]] = rtl.add %arg0, %arg1
// CHECK-NEXT: return %[[RES:.*]]

func @add_identity(%arg0: i11, %arg1: i11) -> i11 {
%c0_i11 = rtl.constant(0 : i11) : i11
Expand All @@ -103,8 +103,8 @@ func @add_identity(%arg0: i11, %arg1: i11) -> i11 {
}

// CHECK-LABEL: func @mul_identity(%arg0: i11, %arg1: i11) -> i11 {
// CHECK-NEXT: %0 = rtl.mul %arg0, %arg1
// CHECK-NEXT: return %0
// CHECK-NEXT: %[[RES:.*]] = rtl.mul %arg0, %arg1
// CHECK-NEXT: return %[[RES:.*]]

func @mul_identity(%arg0: i11, %arg1: i11) -> i11 {
%c1_i11 = rtl.constant(1 : i11) : i11
Expand Down