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 1 commit
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
Prev Previous commit
Removed pattern matching for constants
  • Loading branch information
amaleewilson committed Jul 29, 2020
commit 77aa6d1392c569b31c2447d6be34ce962908c77c
6 changes: 3 additions & 3 deletions test/rtl/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

// CHECK-LABEL: func @test1(%arg0: i3) -> i50 {
func @test1(%arg0: i3) -> i50 {
// CHECK-NEXT: %[[C42_i12:.*]] = rtl.constant(42 : i12) : i12
// CHECK-NEXT: %[[RES0:.*]] = rtl.add %[[C42_i12:.*]], %[[C42_i12:.*]] : i12
// CHECK-NEXT: %[[RES1:.*]] = rtl.mul %[[C42_i12:.*]], %[[RES0:.*]] : i12
// CHECK-NEXT: %c42_i12 = rtl.constant(42 : i12) : 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
Expand Down
16 changes: 8 additions & 8 deletions test/rtl/canonicalization.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ func @extract_noop(%arg0: i3) -> i3 {
}

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

func @extract_cstfold() -> i3 {
%c42_i12 = rtl.constant(42 : i12) : i12
Expand All @@ -31,8 +31,8 @@ func @variadic_noop(%arg0: i11) -> i11 {
}

// CHECK-LABEL: func @and_annulment(%arg0: i11, %arg1: i11) -> i11 {
// CHECK-NEXT: %[[C0_i11:.*]] = rtl.constant(0 : i11)
// CHECK-NEXT: return %[[C0_i11:.*]]
// CHECK-NEXT: %c0_i11 = rtl.constant(0 : i11)
// CHECK-NEXT: return %c0_i11

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

// CHECK-LABEL: func @or_annulment(%arg0: i11) -> i11 {
// CHECK-NEXT: %[[C1_i11:.*]] = rtl.constant(-1 : i11)
// CHECK-NEXT: return %[[C1_i11:.*]]
// CHECK-NEXT: %c-1_i11 = rtl.constant(-1 : i11)
// CHECK-NEXT: return %c-1_i11

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

// CHECK-LABEL: func @mul_annulment(%arg0: i11, %arg1: i11, %arg2: i11) -> i11 {
// CHECK-NEXT: %[[C0_i11:.*]] = rtl.constant(0 : i11) : i11
// CHECK-NEXT: return %[[C0_i11:.*]]
// CHECK-NEXT: %c0_i11 = rtl.constant(0 : i11) : i11
// CHECK-NEXT: return %c0_i11

func @mul_annulment(%arg0: i11, %arg1: i11, %arg2: i11) -> i11 {
%c0_i11 = rtl.constant(0 : i11) : i11
Expand Down