blob: 0fc822b0a23ae0dcfcdd0b8f16ce222fcb9d3bbd [file] [log] [blame]
rkayaith13bd4102022-10-18 18:44:111// RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(canonicalize))' | FileCheck %s
Mehdi Aminia5062792024-06-14 20:38:562// RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(canonicalize{region-simplify=disabled}))' | FileCheck %s --check-prefixes=CHECK,NO-RS
Andy Ly55f2e242019-08-06 18:08:223
Andy Ly6a501e32019-08-26 16:44:094// CHECK-LABEL: func @remove_op_with_inner_ops_pattern
River Riddlecda6aa72022-04-20 23:22:215func.func @remove_op_with_inner_ops_pattern() {
Andy Ly55f2e242019-08-06 18:08:226 // CHECK-NEXT: return
Andy Ly6a501e32019-08-26 16:44:097 "test.op_with_region_pattern"() ({
Mehdi Aminia1d5bdf2021-02-04 01:53:598 "test.op_with_region_terminator"() : () -> ()
Andy Ly55f2e242019-08-06 18:08:229 }) : () -> ()
10 return
11}
Andy Ly6a501e32019-08-26 16:44:0912
13// CHECK-LABEL: func @remove_op_with_inner_ops_fold_no_side_effect
River Riddlecda6aa72022-04-20 23:22:2114func.func @remove_op_with_inner_ops_fold_no_side_effect() {
Andy Ly6a501e32019-08-26 16:44:0915 // CHECK-NEXT: return
16 "test.op_with_region_fold_no_side_effect"() ({
Mehdi Aminia1d5bdf2021-02-04 01:53:5917 "test.op_with_region_terminator"() : () -> ()
Andy Ly6a501e32019-08-26 16:44:0918 }) : () -> ()
19 return
20}
21
22// CHECK-LABEL: func @remove_op_with_inner_ops_fold
23// CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32)
River Riddlecda6aa72022-04-20 23:22:2124func.func @remove_op_with_inner_ops_fold(%arg0 : i32) -> (i32) {
Andy Ly6a501e32019-08-26 16:44:0925 // CHECK-NEXT: return %[[ARG_0]]
26 %0 = "test.op_with_region_fold"(%arg0) ({
Mehdi Aminia1d5bdf2021-02-04 01:53:5927 "test.op_with_region_terminator"() : () -> ()
Andy Ly6a501e32019-08-26 16:44:0928 }) : (i32) -> (i32)
29 return %0 : i32
30}
Parker Schuh309b4552019-10-10 03:42:3231
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 Riddlecda6aa72022-04-20 23:22:2134func.func @remove_op_with_variadic_results_and_folder(%arg0 : i32, %arg1 : i32) -> (i32, i32) {
Parker Schuh309b4552019-10-10 03:42:3235 // 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 Neuendorfferb80a9ca2019-12-09 22:27:1139
40// CHECK-LABEL: func @test_commutative_multi
41// CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32, %[[ARG_1:[a-z0-9]*]]: i32)
River Riddlecda6aa72022-04-20 23:22:2142func.func @test_commutative_multi(%arg0: i32, %arg1: i32) -> (i32, i32) {
Mogballa54f4ea2021-10-12 23:14:5743 // 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 Neuendorfferb80a9ca2019-12-09 22:27:1147 // 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 Aminia1d5bdf2021-02-04 01:53:5955
Chris Lattnerb2f232b2021-03-20 00:57:4756
57// CHECK-LABEL: func @test_commutative_multi_cst
River Riddlecda6aa72022-04-20 23:22:2158func.func @test_commutative_multi_cst(%arg0: i32, %arg1: i32) -> (i32, i32) {
Mogballa54f4ea2021-10-12 23:14:5759 // CHECK-NEXT: %c42_i32 = arith.constant 42 : i32
60 %c42_i32 = arith.constant 42 : i32
61 %c42_i32_2 = arith.constant 42 : i32
Chris Lattnerb2f232b2021-03-20 00:57:4762 // 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
Mogballa54f4ea2021-10-12 23:14:5765 %c42_i32_3 = arith.constant 42 : i32
Chris Lattnerb2f232b2021-03-20 00:57:4766
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 Springer108ca7a2021-05-27 08:26:4573// CHECK-LABEL: test_dialect_canonicalizer
River Riddlecda6aa72022-04-20 23:22:2174func.func @test_dialect_canonicalizer() -> (i32) {
Matthias Springer108ca7a2021-05-27 08:26:4575 %0 = "test.dialect_canonicalizable"() : () -> (i32)
Mogballa54f4ea2021-10-12 23:14:5776 // CHECK: %[[CST:.*]] = arith.constant 42 : i32
Matthias Springer108ca7a2021-05-27 08:26:4577 // CHECK: return %[[CST]]
78 return %0 : i32
79}
rkayaithebad5fb2022-05-18 07:27:5480
81// Check that the option to control region simplification actually works
82// CHECK-LABEL: test_region_simplify
83func.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}