From b279906d783fb8337400ea646ce840ac15af2675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20M=C3=BCller?= Date: Fri, 31 May 2024 12:36:39 +0000 Subject: [PATCH] [Substrait] Add end-to-end test for emit deduplication in `project`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a test for the combine effect of all `project`-related patterns in the emit deduplication pass. Signed-off-by: Ingo Müller --- .../Substrait/emit-deduplication.mlir | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/Transforms/Substrait/emit-deduplication.mlir b/test/Transforms/Substrait/emit-deduplication.mlir index b47ccd44d49a..a353d22a74db 100644 --- a/test/Transforms/Substrait/emit-deduplication.mlir +++ b/test/Transforms/Substrait/emit-deduplication.mlir @@ -294,3 +294,35 @@ substrait.plan version 0 : 42 : 1 { yield %1 : tuple } } + +// ----- + +// End-to-end test of many patterns related to `project`. +// +// The example has duplicates in various places: (1) duplicate emit field in +// `%1`, (2) those are forwarded in the unmofified fields of the `project` in +// `%2`, (3) the two `field_references` ultimately refer to the same field, +// so (4) the `yield` of the `project` op yields duplicates, which are (5) +// both duplicates of the existing fields of the input to `project`. Through +// repeated pattern application, each duplicate is removed, making the next one +// obivous, until the `project` is empty and folded away. + +// CHECK-LABEL: substrait.plan +// CHECK-NEXT: relation +// CHECK-NEXT: %[[V0:.*]] = named_table +// CHECK-NEXT: %[[V1:.*]] = emit [1, 1, 1, 1] from %[[V0]] : +// CHECK-NEXT: yield %[[V1]] : tuple + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a", "b"] : tuple + %1 = emit [1, 1] from %0 : tuple -> tuple + %2 = project %1 : tuple -> tuple { + ^bb0(%arg : tuple): + %3 = field_reference %arg[[0]] : tuple + %4 = field_reference %arg[[1]] : tuple + yield %3, %4 : si32, si32 + } + yield %2 : tuple + } +}