1 // RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(canonicalize))' | FileCheck %s
2 // RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(canonicalize{region-simplify=disabled}))' | FileCheck %s --check-prefixes=CHECK,NO-RS
4 // CHECK-LABEL: func @remove_op_with_inner_ops_pattern
5 func.func @remove_op_with_inner_ops_pattern() {
7 "test.op_with_region_pattern"() ({
8 "test.op_with_region_terminator"() : () -> ()
13 // CHECK-LABEL: func @remove_op_with_inner_ops_fold_no_side_effect
14 func.func @remove_op_with_inner_ops_fold_no_side_effect() {
16 "test.op_with_region_fold_no_side_effect"() ({
17 "test.op_with_region_terminator"() : () -> ()
22 // CHECK-LABEL: func @remove_op_with_inner_ops_fold
23 // CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32)
24 func.func @remove_op_with_inner_ops_fold(%arg0 : i32) -> (i32) {
25 // CHECK-NEXT: return %[[ARG_0]]
26 %0 = "test.op_with_region_fold"(%arg0) ({
27 "test.op_with_region_terminator"() : () -> ()
32 // CHECK-LABEL: func @remove_op_with_variadic_results_and_folder
33 // CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32, %[[ARG_1:[a-z0-9]*]]: i32)
34 func.func @remove_op_with_variadic_results_and_folder(%arg0 : i32, %arg1 : i32) -> (i32, i32) {
35 // CHECK-NEXT: return %[[ARG_0]], %[[ARG_1]]
36 %0, %1 = "test.op_with_variadic_results_and_folder"(%arg0, %arg1) : (i32, i32) -> (i32, i32)
37 return %0, %1 : i32, i32
40 // CHECK-LABEL: func @test_commutative_multi
41 // CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32, %[[ARG_1:[a-z0-9]*]]: i32)
42 func.func @test_commutative_multi(%arg0: i32, %arg1: i32) -> (i32, i32) {
43 // CHECK-DAG: %[[C42:.*]] = arith.constant 42 : i32
44 %c42_i32 = arith.constant 42 : i32
45 // CHECK-DAG: %[[C43:.*]] = arith.constant 43 : i32
46 %c43_i32 = arith.constant 43 : i32
47 // CHECK-NEXT: %[[O0:.*]] = "test.op_commutative"(%[[ARG_0]], %[[ARG_1]], %[[C42]], %[[C43]]) : (i32, i32, i32, i32) -> i32
48 %y = "test.op_commutative"(%c42_i32, %arg0, %arg1, %c43_i32) : (i32, i32, i32, i32) -> i32
50 // CHECK-NEXT: %[[O1:.*]] = "test.op_commutative"(%[[ARG_0]], %[[ARG_1]], %[[C42]], %[[C43]]) : (i32, i32, i32, i32) -> i32
51 %z = "test.op_commutative"(%arg0, %c42_i32, %c43_i32, %arg1): (i32, i32, i32, i32) -> i32
52 // CHECK-NEXT: return %[[O0]], %[[O1]]
53 return %y, %z: i32, i32
57 // CHECK-LABEL: func @test_commutative_multi_cst
58 func.func @test_commutative_multi_cst(%arg0: i32, %arg1: i32) -> (i32, i32) {
59 // CHECK-NEXT: %c42_i32 = arith.constant 42 : i32
60 %c42_i32 = arith.constant 42 : i32
61 %c42_i32_2 = arith.constant 42 : i32
62 // CHECK-NEXT: %[[O0:.*]] = "test.op_commutative"(%arg0, %arg1, %c42_i32, %c42_i32) : (i32, i32, i32, i32) -> i32
63 %y = "test.op_commutative"(%c42_i32, %arg0, %arg1, %c42_i32_2) : (i32, i32, i32, i32) -> i32
65 %c42_i32_3 = arith.constant 42 : i32
67 // CHECK-NEXT: %[[O1:.*]] = "test.op_commutative"(%arg0, %arg1, %c42_i32, %c42_i32) : (i32, i32, i32, i32) -> i32
68 %z = "test.op_commutative"(%arg0, %c42_i32_3, %c42_i32_2, %arg1): (i32, i32, i32, i32) -> i32
69 // CHECK-NEXT: return %[[O0]], %[[O1]]
70 return %y, %z: i32, i32
73 // CHECK-LABEL: test_dialect_canonicalizer
74 func.func @test_dialect_canonicalizer() -> (i32) {
75 %0 = "test.dialect_canonicalizable"() : () -> (i32)
76 // CHECK: %[[CST:.*]] = arith.constant 42 : i32
77 // CHECK: return %[[CST]]
81 // Check that the option to control region simplification actually works
82 // CHECK-LABEL: test_region_simplify
83 func.func @test_region_simplify() {