Mehdi Amini | a1d5bdf | 2021-02-04 01:53:59 | [diff] [blame] | 1 | // RUN: mlir-opt %s -pass-pipeline='func(canonicalize)' | FileCheck %s |
Andy Ly | 55f2e24 | 2019-08-06 18:08:22 | [diff] [blame] | 2 | |
Andy Ly | 6a501e3 | 2019-08-26 16:44:09 | [diff] [blame] | 3 | // CHECK-LABEL: func @remove_op_with_inner_ops_pattern |
| 4 | func @remove_op_with_inner_ops_pattern() { |
Andy Ly | 55f2e24 | 2019-08-06 18:08:22 | [diff] [blame] | 5 | // CHECK-NEXT: return |
Andy Ly | 6a501e3 | 2019-08-26 16:44:09 | [diff] [blame] | 6 | "test.op_with_region_pattern"() ({ |
Mehdi Amini | a1d5bdf | 2021-02-04 01:53:59 | [diff] [blame] | 7 | "test.op_with_region_terminator"() : () -> () |
Andy Ly | 55f2e24 | 2019-08-06 18:08:22 | [diff] [blame] | 8 | }) : () -> () |
| 9 | return |
| 10 | } |
Andy Ly | 6a501e3 | 2019-08-26 16:44:09 | [diff] [blame] | 11 | |
| 12 | // CHECK-LABEL: func @remove_op_with_inner_ops_fold_no_side_effect |
| 13 | func @remove_op_with_inner_ops_fold_no_side_effect() { |
| 14 | // CHECK-NEXT: return |
| 15 | "test.op_with_region_fold_no_side_effect"() ({ |
Mehdi Amini | a1d5bdf | 2021-02-04 01:53:59 | [diff] [blame] | 16 | "test.op_with_region_terminator"() : () -> () |
Andy Ly | 6a501e3 | 2019-08-26 16:44:09 | [diff] [blame] | 17 | }) : () -> () |
| 18 | return |
| 19 | } |
| 20 | |
| 21 | // CHECK-LABEL: func @remove_op_with_inner_ops_fold |
| 22 | // CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32) |
| 23 | func @remove_op_with_inner_ops_fold(%arg0 : i32) -> (i32) { |
| 24 | // CHECK-NEXT: return %[[ARG_0]] |
| 25 | %0 = "test.op_with_region_fold"(%arg0) ({ |
Mehdi Amini | a1d5bdf | 2021-02-04 01:53:59 | [diff] [blame] | 26 | "test.op_with_region_terminator"() : () -> () |
Andy Ly | 6a501e3 | 2019-08-26 16:44:09 | [diff] [blame] | 27 | }) : (i32) -> (i32) |
| 28 | return %0 : i32 |
| 29 | } |
Parker Schuh | 309b455 | 2019-10-10 03:42:32 | [diff] [blame] | 30 | |
| 31 | // CHECK-LABEL: func @remove_op_with_variadic_results_and_folder |
| 32 | // CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32, %[[ARG_1:[a-z0-9]*]]: i32) |
| 33 | func @remove_op_with_variadic_results_and_folder(%arg0 : i32, %arg1 : i32) -> (i32, i32) { |
| 34 | // CHECK-NEXT: return %[[ARG_0]], %[[ARG_1]] |
| 35 | %0, %1 = "test.op_with_variadic_results_and_folder"(%arg0, %arg1) : (i32, i32) -> (i32, i32) |
| 36 | return %0, %1 : i32, i32 |
| 37 | } |
Stephen Neuendorffer | b80a9ca | 2019-12-09 22:27:11 | [diff] [blame] | 38 | |
| 39 | // CHECK-LABEL: func @test_commutative_multi |
| 40 | // CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32, %[[ARG_1:[a-z0-9]*]]: i32) |
| 41 | func @test_commutative_multi(%arg0: i32, %arg1: i32) -> (i32, i32) { |
Chris Lattner | a004da0 | 2021-05-24 22:45:58 | [diff] [blame] | 42 | // CHECK-DAG: %[[C42:.*]] = constant 42 : i32 |
Stephen Neuendorffer | b80a9ca | 2019-12-09 22:27:11 | [diff] [blame] | 43 | %c42_i32 = constant 42 : i32 |
Chris Lattner | a004da0 | 2021-05-24 22:45:58 | [diff] [blame] | 44 | // CHECK-DAG: %[[C43:.*]] = constant 43 : i32 |
Stephen Neuendorffer | b80a9ca | 2019-12-09 22:27:11 | [diff] [blame] | 45 | %c43_i32 = constant 43 : i32 |
| 46 | // CHECK-NEXT: %[[O0:.*]] = "test.op_commutative"(%[[ARG_0]], %[[ARG_1]], %[[C42]], %[[C43]]) : (i32, i32, i32, i32) -> i32 |
| 47 | %y = "test.op_commutative"(%c42_i32, %arg0, %arg1, %c43_i32) : (i32, i32, i32, i32) -> i32 |
| 48 | |
| 49 | // CHECK-NEXT: %[[O1:.*]] = "test.op_commutative"(%[[ARG_0]], %[[ARG_1]], %[[C42]], %[[C43]]) : (i32, i32, i32, i32) -> i32 |
| 50 | %z = "test.op_commutative"(%arg0, %c42_i32, %c43_i32, %arg1): (i32, i32, i32, i32) -> i32 |
| 51 | // CHECK-NEXT: return %[[O0]], %[[O1]] |
| 52 | return %y, %z: i32, i32 |
| 53 | } |
Mehdi Amini | a1d5bdf | 2021-02-04 01:53:59 | [diff] [blame] | 54 | |
Chris Lattner | b2f232b | 2021-03-20 00:57:47 | [diff] [blame] | 55 | |
| 56 | // CHECK-LABEL: func @test_commutative_multi_cst |
| 57 | func @test_commutative_multi_cst(%arg0: i32, %arg1: i32) -> (i32, i32) { |
| 58 | // CHECK-NEXT: %c42_i32 = constant 42 : i32 |
| 59 | %c42_i32 = constant 42 : i32 |
| 60 | %c42_i32_2 = constant 42 : i32 |
| 61 | // CHECK-NEXT: %[[O0:.*]] = "test.op_commutative"(%arg0, %arg1, %c42_i32, %c42_i32) : (i32, i32, i32, i32) -> i32 |
| 62 | %y = "test.op_commutative"(%c42_i32, %arg0, %arg1, %c42_i32_2) : (i32, i32, i32, i32) -> i32 |
| 63 | |
| 64 | %c42_i32_3 = constant 42 : i32 |
| 65 | |
| 66 | // CHECK-NEXT: %[[O1:.*]] = "test.op_commutative"(%arg0, %arg1, %c42_i32, %c42_i32) : (i32, i32, i32, i32) -> i32 |
| 67 | %z = "test.op_commutative"(%arg0, %c42_i32_3, %c42_i32_2, %arg1): (i32, i32, i32, i32) -> i32 |
| 68 | // CHECK-NEXT: return %[[O0]], %[[O1]] |
| 69 | return %y, %z: i32, i32 |
| 70 | } |
| 71 | |
| 72 | // CHECK-LABEL: func @typemismatch |
| 73 | |
Mehdi Amini | a1d5bdf | 2021-02-04 01:53:59 | [diff] [blame] | 74 | func @typemismatch() -> i32 { |
| 75 | %c42 = constant 42.0 : f32 |
| 76 | |
| 77 | // The "passthrough_fold" folder will naively return its operand, but we don't |
| 78 | // want to fold here because of the type mismatch. |
| 79 | |
| 80 | // CHECK: "test.passthrough_fold" |
| 81 | %0 = "test.passthrough_fold"(%c42) : (f32) -> (i32) |
| 82 | return %0 : i32 |
| 83 | } |
MaheshRavishankar | 9b05170 | 2021-03-29 17:57:23 | [diff] [blame] | 84 | |
| 85 | // CHECK-LABEL: func @result_shape_per_dim |
| 86 | // CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: tensor<2x3x?xf32>, %[[ARG_1:[a-z0-9]*]]: tensor<?x5xf32>) |
| 87 | func @result_shape_per_dim(%arg0 : tensor<2x3x?xf32>, %arg1 : tensor<?x5xf32>) |
| 88 | -> (index, index, index, index, index) { |
| 89 | // CHECK-DAG: %[[C0:.+]] = constant 0 : index |
| 90 | // CHECK-DAG: %[[C2:.+]] = constant 2 : index |
| 91 | // CHECK-DAG: %[[C3:.+]] = constant 3 : index |
| 92 | // CHECK-DAG: %[[C5:.+]] = constant 5 : index |
| 93 | %c0 = constant 0 : index |
| 94 | %c1 = constant 1 : index |
| 95 | %c2 = constant 2 : index |
| 96 | %0:2 = "test.op_with_result_shape_per_dim_interface"(%arg0, %arg1) |
| 97 | : (tensor<2x3x?xf32>, tensor<?x5xf32>) -> (tensor<?x5xf32>, tensor<2x3x?xf32>) |
| 98 | %1 = memref.dim %0#0, %c0 : tensor<?x5xf32> |
| 99 | %2 = memref.dim %0#0, %c1 : tensor<?x5xf32> |
| 100 | %3 = memref.dim %0#1, %c0 : tensor<2x3x?xf32> |
| 101 | %4 = memref.dim %0#1, %c1 : tensor<2x3x?xf32> |
| 102 | %5 = memref.dim %0#1, %c2 : tensor<2x3x?xf32> |
| 103 | // CHECK-DAG: %[[D0:.+]] = memref.dim %[[ARG_1]], %[[C0]] |
| 104 | // CHECK-DAG: %[[D1:.+]] = memref.dim %[[ARG_0]], %[[C2]] |
| 105 | // CHECK: return %[[D0]], %[[C5]], %[[C2]], %[[C3]], %[[D1]] |
| 106 | return %1, %2, %3, %4, %5 : index, index, index, index, index |
Matthias Springer | 108ca7a | 2021-05-27 08:26:45 | [diff] [blame^] | 107 | } |
| 108 | |
| 109 | // CHECK-LABEL: test_dialect_canonicalizer |
| 110 | func @test_dialect_canonicalizer() -> (i32) { |
| 111 | %0 = "test.dialect_canonicalizable"() : () -> (i32) |
| 112 | // CHECK: %[[CST:.*]] = constant 42 : i32 |
| 113 | // CHECK: return %[[CST]] |
| 114 | return %0 : i32 |
| 115 | } |