Skip to content

Commit

Permalink
Fix tests of emit deduplication pass.
Browse files Browse the repository at this point in the history
In the meantime, `main` contains tests that used `func.call` ops to
prevent further pattern application. This breaks with this PR, which
makes `plan`s a `SymbolTable`, which become the closest symbol table of
the `func.call`s, such that those symbols cannot be found anymore. As a
solution, this commit changes the unit tests to use an opaque op from an
unregistered dialect.

Signed-off-by: Ingo Müller <[email protected]>
  • Loading branch information
ingomueller-net committed Jul 31, 2024
1 parent f94574d commit 35b8f45
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions test/Transforms/Substrait/emit-deduplication.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: structured-opt -split-input-file %s -substrait-emit-deduplication \
// RUN: structured-opt -split-input-file %s \
// RUN: -substrait-emit-deduplication -allow-unregistered-dialect \
// RUN: | FileCheck %s

// `cross` op with left `emit` input with duplicates.
Expand Down Expand Up @@ -165,13 +166,11 @@ substrait.plan version 0 : 42 : 1 {
// CHECK-NEXT: %[[V6:.*]] = field_reference %[[ARG0]][1] : [[TYPE]]
// CHECK-NEXT: %[[V7:.*]] = field_reference %[[V6]][1] :
// CHECK-NEXT: %[[V9:.*]] = field_reference %[[ARG0]][2] : [[TYPE]]
// CHECK-NEXT: %[[Va:.*]] = func.call @f(%[[V3]], %[[V3]], %[[V5]], %[[V7]], %[[V3]], %[[V9]])
// CHECK-NEXT: %[[Va:.*]] = "test.op"(%[[V3]], %[[V3]], %[[V5]], %[[V7]], %[[V3]], %[[V9]])
// CHECK-NEXT: yield %[[Va]] : si1
// CHECK-NEXT: }
// CHECK-NEXT: %[[Vb:.*]] = emit [0, 0, 1, 0, 2] from %[[V2]]

func.func private @f(si1, si1, si1, si32, si1, si1) -> si1

substrait.plan version 0 : 42 : 1 {
relation {
%0 = named_table @t1 as ["a", "b", "c", "d", "e"] : tuple<si1, si1, tuple<si1, si32>>
Expand All @@ -189,7 +188,7 @@ substrait.plan version 0 : 42 : 1 {
%7 = field_reference %6[1] : tuple<si1, si32>
%8 = field_reference %arg0[3] : tuple<si1, si1, tuple<si1, si32>, si1, si1>
%9 = field_reference %arg0[4] : tuple<si1, si1, tuple<si1, si32>, si1, si1>
%a = func.call @f(%3, %4, %5, %7, %8, %9) : (si1, si1, si1, si32, si1, si1) -> si1
%a = "test.op"(%3, %4, %5, %7, %8, %9) : (si1, si1, si1, si32, si1, si1) -> si1
yield %a : si1
}
yield %2 : tuple<si1, si1, tuple<si1, si32>, si1, si1>
Expand All @@ -207,13 +206,11 @@ substrait.plan version 0 : 42 : 1 {
// CHECK-NEXT: %[[V2:.*]] = project %[[V1]] : tuple<si32> -> tuple<si32, si1> {
// CHECK-NEXT: ^{{.*}}(%[[ARG0:.*]]: [[TYPE:.*]]):
// CHECK-NEXT: %[[V3:.*]] = field_reference %[[ARG0]][0] : [[TYPE]]
// CHECK-NEXT: %[[V5:.*]] = func.call @f(%[[V3]], %[[V3]]) :
// CHECK-NEXT: %[[V5:.*]] = "test.op"(%[[V3]], %[[V3]]) :
// CHECK-NEXT: yield %[[V5]] : si1
// CHECK-NEXT: }
// CHECK-NEXT: %[[V6:.*]] = emit [0, 0, 1] from %[[V2]]

func.func private @f(si32, si32) -> si1

substrait.plan version 0 : 42 : 1 {
relation {
%0 = named_table @t1 as ["a", "b"] : tuple<si1, si32>
Expand All @@ -222,7 +219,7 @@ substrait.plan version 0 : 42 : 1 {
^bb0(%arg : tuple<si32, si32>):
%3 = field_reference %arg[0] : tuple<si32, si32>
%4 = field_reference %arg[1] : tuple<si32, si32>
%5 = func.call @f(%3, %4) : (si32, si32) -> si1
%5 = "test.op"(%3, %4) : (si32, si32) -> si1
yield %5 : si1
}
yield %2 : tuple<si32, si32, si1>
Expand All @@ -239,20 +236,18 @@ substrait.plan version 0 : 42 : 1 {
// CHECK-NEXT: %[[V1:.*]] = project %[[V0]] : {{.*}} {
// CHECK-NEXT: ^{{.*}}(%[[ARG0:.*]]: [[TYPE:.*]]):
// CHECK-NEXT: %[[V2:.*]] = field_reference %[[ARG0]][0] : [[TYPE]]
// CHECK-NEXT: %[[V3:.*]] = func.call @f(%[[V2]]) :
// CHECK-NEXT: %[[V3:.*]] = "test.op"(%[[V2]]) :
// CHECK-NEXT: yield %[[V3]] : si1
// CHECK-NEXT: }
// CHECK-NEXT: %[[V4:.*]] = emit [0, 1, 1] from %[[V1]]

func.func private @f(si32) -> si1

substrait.plan version 0 : 42 : 1 {
relation {
%0 = named_table @t1 as ["a"] : tuple<si32>
%1 = project %0 : tuple<si32> -> tuple<si32, si1, si1> {
^bb0(%arg : tuple<si32>):
%2 = field_reference %arg[0] : tuple<si32>
%3 = func.call @f(%2) : (si32) -> si1
%3 = "test.op"(%2) : (si32) -> si1
// We yield two times the same value. This pattern should remove one of
// the two and re-establish the duplicate with an `amit` after the
// `project`.
Expand All @@ -272,20 +267,18 @@ substrait.plan version 0 : 42 : 1 {
// CHECK-NEXT: %[[V1:.*]] = project %[[V0]] : {{.*}} {
// CHECK-NEXT: ^{{.*}}(%[[ARG0:.*]]: [[TYPE:.*]]):
// CHECK-NEXT: %[[V2:.*]] = field_reference %[[ARG0]][0] : [[TYPE]]
// CHECK-NEXT: %[[V3:.*]] = func.call @f(%[[V2]]) :
// CHECK-NEXT: %[[V3:.*]] = "test.op"(%[[V2]]) :
// CHECK-NEXT: yield %[[V3]] : si1
// CHECK-NEXT: }
// CHECK-NEXT: %[[V4:.*]] = emit [0, 1, 0, 2] from %[[V1]]

func.func private @f(si32) -> si1

substrait.plan version 0 : 42 : 1 {
relation {
%0 = named_table @t1 as ["a", "b"] : tuple<si32, si1>
%1 = project %0 : tuple<si32, si1> -> tuple<si32, si1, si32, si1> {
^bb0(%arg0: tuple<si32, si1>):
%2 = field_reference %arg0[0] : tuple<si32, si1>
%3 = func.call @f(%2) : (si32) -> si1
%3 = "test.op"(%2) : (si32) -> si1
// `%2` yields an input field without modifications. This pattern removes
// that yielding and re-establishes the duplicated field with an `emit`
// following the `project` instead.
Expand Down

0 comments on commit 35b8f45

Please sign in to comment.