90 lines · plain
1// RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(canonicalize))' | FileCheck %s --check-prefixes=CHECK,RS2// RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(canonicalize{region-simplify=disabled}))' | FileCheck %s --check-prefixes=CHECK,NO-RS3 4// CHECK-LABEL: func @remove_op_with_inner_ops_pattern5func.func @remove_op_with_inner_ops_pattern() {6 // CHECK-NEXT: return7 "test.op_with_region_pattern"() ({8 "test.op_with_region_terminator"() : () -> ()9 }) : () -> ()10 return11}12 13// CHECK-LABEL: func @remove_op_with_inner_ops_fold_no_side_effect14func.func @remove_op_with_inner_ops_fold_no_side_effect() {15 // CHECK-NEXT: return16 "test.op_with_region_fold_no_side_effect"() ({17 "test.op_with_region_terminator"() : () -> ()18 }) : () -> ()19 return20}21 22// CHECK-LABEL: func @remove_op_with_inner_ops_fold23// CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32)24func.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"() : () -> ()28 }) : (i32) -> (i32)29 return %0 : i3230}31 32// CHECK-LABEL: func @remove_op_with_variadic_results_and_folder33// CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32, %[[ARG_1:[a-z0-9]*]]: i32)34func.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, i3238}39 40// CHECK-LABEL: func @test_commutative_multi41// CHECK-SAME: (%[[ARG_0:[a-z0-9]*]]: i32, %[[ARG_1:[a-z0-9]*]]: i32)42func.func @test_commutative_multi(%arg0: i32, %arg1: i32) -> (i32, i32) {43 // CHECK-DAG: %[[C42:.*]] = arith.constant 42 : i3244 %c42_i32 = arith.constant 42 : i3245 // CHECK-DAG: %[[C43:.*]] = arith.constant 43 : i3246 %c43_i32 = arith.constant 43 : i3247 // CHECK-NEXT: %[[O0:.*]] = "test.op_commutative"(%[[ARG_0]], %[[ARG_1]], %[[C42]], %[[C43]]) : (i32, i32, i32, i32) -> i3248 %y = "test.op_commutative"(%c42_i32, %arg0, %arg1, %c43_i32) : (i32, i32, i32, i32) -> i3249 50 // CHECK-NEXT: %[[O1:.*]] = "test.op_commutative"(%[[ARG_0]], %[[ARG_1]], %[[C42]], %[[C43]]) : (i32, i32, i32, i32) -> i3251 %z = "test.op_commutative"(%arg0, %c42_i32, %c43_i32, %arg1): (i32, i32, i32, i32) -> i3252 // CHECK-NEXT: return %[[O0]], %[[O1]]53 return %y, %z: i32, i3254}55 56 57// CHECK-LABEL: func @test_commutative_multi_cst58func.func @test_commutative_multi_cst(%arg0: i32, %arg1: i32) -> (i32, i32) {59 // CHECK-NEXT: %c42_i32 = arith.constant 42 : i3260 %c42_i32 = arith.constant 42 : i3261 %c42_i32_2 = arith.constant 42 : i3262 // CHECK-NEXT: %[[O0:.*]] = "test.op_commutative"(%arg0, %arg1, %c42_i32, %c42_i32) : (i32, i32, i32, i32) -> i3263 %y = "test.op_commutative"(%c42_i32, %arg0, %arg1, %c42_i32_2) : (i32, i32, i32, i32) -> i3264 65 %c42_i32_3 = arith.constant 42 : i3266 67 // CHECK-NEXT: %[[O1:.*]] = "test.op_commutative"(%arg0, %arg1, %c42_i32, %c42_i32) : (i32, i32, i32, i32) -> i3268 %z = "test.op_commutative"(%arg0, %c42_i32_3, %c42_i32_2, %arg1): (i32, i32, i32, i32) -> i3269 // CHECK-NEXT: return %[[O0]], %[[O1]]70 return %y, %z: i32, i3271}72 73// CHECK-LABEL: test_dialect_canonicalizer74func.func @test_dialect_canonicalizer() -> (i32) {75 %0 = "test.dialect_canonicalizable"() : () -> (i32)76 // CHECK: %[[CST:.*]] = arith.constant 42 : i3277 // CHECK: return %[[CST]]78 return %0 : i3279}80 81// Check that the option to control region simplification actually works82// CHECK-LABEL: test_region_simplify83func.func @test_region_simplify(%input1 : i32, %cond : i1) -> i32 {84 // RS-NEXT: "test.br"(%arg0)[^bb1] : (i32) -> ()85 // NO-RS-NEXT: "test.br"(%arg0, %arg0)[^bb1] : (i32, i32) -> ()86 "test.br"(%input1, %input1)[^bb1] : (i32, i32) -> ()87^bb1(%used_arg : i32, %unused_arg : i32):88 return %used_arg : i3289}90