rkayaith | 13bd410 | 2022-10-18 18:44:11 | [diff] [blame] | 1 | // RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='builtin.module(func.func(canonicalize{top-down=true}))' | FileCheck %s --check-prefix=TD |
| 2 | // RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='builtin.module(func.func(canonicalize))' | FileCheck %s --check-prefix=BU |
Chris Lattner | 648f34a | 2021-05-17 16:51:45 | [diff] [blame] | 3 | |
| 4 | |
| 5 | // BU-LABEL: func @default_insertion_position |
| 6 | // TD-LABEL: func @default_insertion_position |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 7 | func.func @default_insertion_position(%cond: i1) { |
Chris Lattner | 648f34a | 2021-05-17 16:51:45 | [diff] [blame] | 8 | // Constant should be folded into the entry block. |
| 9 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 10 | // BU: arith.constant 2 |
Chris Lattner | 648f34a | 2021-05-17 16:51:45 | [diff] [blame] | 11 | // BU-NEXT: scf.if |
| 12 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 13 | // TD: arith.constant 2 |
Chris Lattner | 648f34a | 2021-05-17 16:51:45 | [diff] [blame] | 14 | // TD-NEXT: scf.if |
| 15 | scf.if %cond { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 16 | %0 = arith.constant 1 : i32 |
| 17 | %2 = arith.addi %0, %0 : i32 |
Chris Lattner | 648f34a | 2021-05-17 16:51:45 | [diff] [blame] | 18 | "foo.yield"(%2) : (i32) -> () |
| 19 | } |
| 20 | return |
| 21 | } |
| 22 | |
| 23 | // This shows that we don't pull the constant out of the region because it |
| 24 | // wants to be the insertion point for the constant. |
| 25 | // BU-LABEL: func @custom_insertion_position |
| 26 | // TD-LABEL: func @custom_insertion_position |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 27 | func.func @custom_insertion_position() { |
Chris Lattner | 648f34a | 2021-05-17 16:51:45 | [diff] [blame] | 28 | // BU: test.one_region_op |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 29 | // BU-NEXT: arith.constant 2 |
Chris Lattner | 648f34a | 2021-05-17 16:51:45 | [diff] [blame] | 30 | |
| 31 | // TD: test.one_region_op |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 32 | // TD-NEXT: arith.constant 2 |
Chris Lattner | 648f34a | 2021-05-17 16:51:45 | [diff] [blame] | 33 | "test.one_region_op"() ({ |
| 34 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 35 | %0 = arith.constant 1 : i32 |
| 36 | %2 = arith.addi %0, %0 : i32 |
Chris Lattner | 648f34a | 2021-05-17 16:51:45 | [diff] [blame] | 37 | "foo.yield"(%2) : (i32) -> () |
| 38 | }) : () -> () |
| 39 | return |
| 40 | } |
| 41 | |