rkayaith | 13bd410 | 2022-10-18 18:44:11 | [diff] [blame] | 1 | // RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(canonicalize))' | FileCheck %s |
Mehdi Amini | a506279 | 2024-06-14 20:38:56 | [diff] [blame] | 2 | // RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(canonicalize{region-simplify=disabled}))' | FileCheck %s --check-prefixes=CHECK,NO-RS |
Andy Ly | 55f2e24 | 2019-08-06 18:08:22 | [diff] [blame] | 3 | |
Andy Ly | 6a501e3 | 2019-08-26 16:44:09 | [diff] [blame] | 4 | // CHECK-LABEL: func @remove_op_with_inner_ops_pattern |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 5 | func.func @remove_op_with_inner_ops_pattern() { |
Andy Ly | 55f2e24 | 2019-08-06 18:08:22 | [diff] [blame] | 6 | // CHECK-NEXT: return |
Andy Ly | 6a501e3 | 2019-08-26 16:44:09 | [diff] [blame] | 7 | "test.op_with_region_pattern"() ({ |
Mehdi Amini | a1d5bdf | 2021-02-04 01:53:59 | [diff] [blame] | 8 | "test.op_with_region_terminator"() : () -> () |
Andy Ly | 55f2e24 | 2019-08-06 18:08:22 | [diff] [blame] | 9 | }) : () -> () |
| 10 | return |
| 11 | } |
Andy Ly | 6a501e3 | 2019-08-26 16:44:09 | [diff] [blame] | 12 | |
| 13 | // CHECK-LABEL: func @remove_op_with_inner_ops_fold_no_side_effect |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 14 | func.func @remove_op_with_inner_ops_fold_no_side_effect() { |
Andy Ly | 6a501e3 | 2019-08-26 16:44:09 | [diff] [blame] | 15 | // CHECK-NEXT: return |
| 16 | "test.op_with_region_fold_no_side_effect"() ({ |
Mehdi Amini | a1d5bdf | 2021-02-04 01:53:59 | [diff] [blame] | 17 | "test.op_with_region_terminator"() : () -> () |
Andy Ly | 6a501e3 | 2019-08-26 16:44:09 | [diff] [blame] | 18 | }) : () -> () |
| 19 | return |
| 20 | } |
| 21 | |
| 22 | // CHECK-LABEL: func @remove_op_with_inner_ops_fold |
| 23 | // CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32) |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 24 | func.func @remove_op_with_inner_ops_fold(%arg0 : i32) -> (i32) { |
Andy Ly | 6a501e3 | 2019-08-26 16:44:09 | [diff] [blame] | 25 | // CHECK-NEXT: return %[[ARG_0]] |
| 26 | %0 = "test.op_with_region_fold"(%arg0) ({ |
Mehdi Amini | a1d5bdf | 2021-02-04 01:53:59 | [diff] [blame] | 27 | "test.op_with_region_terminator"() : () -> () |
Andy Ly | 6a501e3 | 2019-08-26 16:44:09 | [diff] [blame] | 28 | }) : (i32) -> (i32) |
| 29 | return %0 : i32 |
| 30 | } |
Parker Schuh | 309b455 | 2019-10-10 03:42:32 | [diff] [blame] | 31 | |
| 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) |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 34 | func.func @remove_op_with_variadic_results_and_folder(%arg0 : i32, %arg1 : i32) -> (i32, i32) { |
Parker Schuh | 309b455 | 2019-10-10 03:42:32 | [diff] [blame] | 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 |
| 38 | } |
Stephen Neuendorffer | b80a9ca | 2019-12-09 22:27:11 | [diff] [blame] | 39 | |
| 40 | // CHECK-LABEL: func @test_commutative_multi |
| 41 | // CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32, %[[ARG_1:[a-z0-9]*]]: i32) |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 42 | func.func @test_commutative_multi(%arg0: i32, %arg1: i32) -> (i32, i32) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 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 |
Stephen Neuendorffer | b80a9ca | 2019-12-09 22:27:11 | [diff] [blame] | 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 |
| 49 | |
| 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 |
| 54 | } |
Mehdi Amini | a1d5bdf | 2021-02-04 01:53:59 | [diff] [blame] | 55 | |
Chris Lattner | b2f232b | 2021-03-20 00:57:47 | [diff] [blame] | 56 | |
| 57 | // CHECK-LABEL: func @test_commutative_multi_cst |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 58 | func.func @test_commutative_multi_cst(%arg0: i32, %arg1: i32) -> (i32, i32) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 59 | // CHECK-NEXT: %c42_i32 = arith.constant 42 : i32 |
| 60 | %c42_i32 = arith.constant 42 : i32 |
| 61 | %c42_i32_2 = arith.constant 42 : i32 |
Chris Lattner | b2f232b | 2021-03-20 00:57:47 | [diff] [blame] | 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 |
| 64 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 65 | %c42_i32_3 = arith.constant 42 : i32 |
Chris Lattner | b2f232b | 2021-03-20 00:57:47 | [diff] [blame] | 66 | |
| 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 |
| 71 | } |
| 72 | |
Matthias Springer | 108ca7a | 2021-05-27 08:26:45 | [diff] [blame] | 73 | // CHECK-LABEL: test_dialect_canonicalizer |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 74 | func.func @test_dialect_canonicalizer() -> (i32) { |
Matthias Springer | 108ca7a | 2021-05-27 08:26:45 | [diff] [blame] | 75 | %0 = "test.dialect_canonicalizable"() : () -> (i32) |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 76 | // CHECK: %[[CST:.*]] = arith.constant 42 : i32 |
Matthias Springer | 108ca7a | 2021-05-27 08:26:45 | [diff] [blame] | 77 | // CHECK: return %[[CST]] |
| 78 | return %0 : i32 |
| 79 | } |
rkayaith | ebad5fb | 2022-05-18 07:27:54 | [diff] [blame] | 80 | |
| 81 | // Check that the option to control region simplification actually works |
| 82 | // CHECK-LABEL: test_region_simplify |
| 83 | func.func @test_region_simplify() { |
| 84 | // CHECK-NEXT: return |
| 85 | // NO-RS-NEXT: ^bb1 |
| 86 | // NO-RS-NEXT: return |
| 87 | // CHECK-NEXT: } |
| 88 | return |
| 89 | ^bb1: |
| 90 | return |
| 91 | } |