blob: 33a1db5d8d17da81ef9334af47ffebb82efc0ecf [file] [log] [blame]
River Riddle36550692022-03-08 03:16:031// RUN: mlir-opt %s -pass-pipeline='func.func(canonicalize)' | FileCheck %s
Andy Ly55f2e242019-08-06 18:08:222
Andy Ly6a501e32019-08-26 16:44:093// CHECK-LABEL: func @remove_op_with_inner_ops_pattern
4func @remove_op_with_inner_ops_pattern() {
Andy Ly55f2e242019-08-06 18:08:225 // CHECK-NEXT: return
Andy Ly6a501e32019-08-26 16:44:096 "test.op_with_region_pattern"() ({
Mehdi Aminia1d5bdf2021-02-04 01:53:597 "test.op_with_region_terminator"() : () -> ()
Andy Ly55f2e242019-08-06 18:08:228 }) : () -> ()
9 return
10}
Andy Ly6a501e32019-08-26 16:44:0911
12// CHECK-LABEL: func @remove_op_with_inner_ops_fold_no_side_effect
13func @remove_op_with_inner_ops_fold_no_side_effect() {
14 // CHECK-NEXT: return
15 "test.op_with_region_fold_no_side_effect"() ({
Mehdi Aminia1d5bdf2021-02-04 01:53:5916 "test.op_with_region_terminator"() : () -> ()
Andy Ly6a501e32019-08-26 16:44:0917 }) : () -> ()
18 return
19}
20
21// CHECK-LABEL: func @remove_op_with_inner_ops_fold
22// CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32)
23func @remove_op_with_inner_ops_fold(%arg0 : i32) -> (i32) {
24 // CHECK-NEXT: return %[[ARG_0]]
25 %0 = "test.op_with_region_fold"(%arg0) ({
Mehdi Aminia1d5bdf2021-02-04 01:53:5926 "test.op_with_region_terminator"() : () -> ()
Andy Ly6a501e32019-08-26 16:44:0927 }) : (i32) -> (i32)
28 return %0 : i32
29}
Parker Schuh309b4552019-10-10 03:42:3230
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)
33func @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 Neuendorfferb80a9ca2019-12-09 22:27:1138
39// CHECK-LABEL: func @test_commutative_multi
40// CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32, %[[ARG_1:[a-z0-9]*]]: i32)
41func @test_commutative_multi(%arg0: i32, %arg1: i32) -> (i32, i32) {
Mogballa54f4ea2021-10-12 23:14:5742 // CHECK-DAG: %[[C42:.*]] = arith.constant 42 : i32
43 %c42_i32 = arith.constant 42 : i32
44 // CHECK-DAG: %[[C43:.*]] = arith.constant 43 : i32
45 %c43_i32 = arith.constant 43 : i32
Stephen Neuendorfferb80a9ca2019-12-09 22:27:1146 // 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 Aminia1d5bdf2021-02-04 01:53:5954
Chris Lattnerb2f232b2021-03-20 00:57:4755
56// CHECK-LABEL: func @test_commutative_multi_cst
57func @test_commutative_multi_cst(%arg0: i32, %arg1: i32) -> (i32, i32) {
Mogballa54f4ea2021-10-12 23:14:5758 // CHECK-NEXT: %c42_i32 = arith.constant 42 : i32
59 %c42_i32 = arith.constant 42 : i32
60 %c42_i32_2 = arith.constant 42 : i32
Chris Lattnerb2f232b2021-03-20 00:57:4761 // 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
Mogballa54f4ea2021-10-12 23:14:5764 %c42_i32_3 = arith.constant 42 : i32
Chris Lattnerb2f232b2021-03-20 00:57:4765
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 Aminia1d5bdf2021-02-04 01:53:5974func @typemismatch() -> i32 {
Mogballa54f4ea2021-10-12 23:14:5775 %c42 = arith.constant 42.0 : f32
Mehdi Aminia1d5bdf2021-02-04 01:53:5976
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}
MaheshRavishankar9b051702021-03-29 17:57:2384
Matthias Springer108ca7a2021-05-27 08:26:4585// CHECK-LABEL: test_dialect_canonicalizer
86func @test_dialect_canonicalizer() -> (i32) {
87 %0 = "test.dialect_canonicalizable"() : () -> (i32)
Mogballa54f4ea2021-10-12 23:14:5788 // CHECK: %[[CST:.*]] = arith.constant 42 : i32
Matthias Springer108ca7a2021-05-27 08:26:4589 // CHECK: return %[[CST]]
90 return %0 : i32
91}