Matthias Springer | e7790fb | 2023-01-04 10:39:41 | [diff] [blame] | 1 | // RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='builtin.module(func.func(canonicalize{test-convergence}))' -split-input-file | FileCheck %s |
Andy Davis | a4669cd | 2019-11-14 20:22:28 | [diff] [blame] | 2 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 3 | // CHECK-LABEL: func @test_subi_zero |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 4 | func.func @test_subi_zero(%arg0: i32) -> i32 { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 5 | // CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 |
Chris Lattner | a03051b | 2018-10-22 20:08:27 | [diff] [blame] | 6 | // CHECK-NEXT: return %c0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 7 | %y = arith.subi %arg0, %arg0 : i32 |
Chris Lattner | a03051b | 2018-10-22 20:08:27 | [diff] [blame] | 8 | return %y: i32 |
| 9 | } |
| 10 | |
Stephan Herhut | af016ba | 2019-04-08 12:53:59 | [diff] [blame] | 11 | // CHECK-LABEL: func @test_subi_zero_vector |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 12 | func.func @test_subi_zero_vector(%arg0: vector<4xi32>) -> vector<4xi32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 13 | //CHECK-NEXT: %cst = arith.constant dense<0> : vector<4xi32> |
| 14 | %y = arith.subi %arg0, %arg0 : vector<4xi32> |
Stephan Herhut | af016ba | 2019-04-08 12:53:59 | [diff] [blame] | 15 | // CHECK-NEXT: return %cst |
| 16 | return %y: vector<4xi32> |
| 17 | } |
| 18 | |
| 19 | // CHECK-LABEL: func @test_subi_zero_tensor |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 20 | func.func @test_subi_zero_tensor(%arg0: tensor<4x5xi32>) -> tensor<4x5xi32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 21 | //CHECK-NEXT: %cst = arith.constant dense<0> : tensor<4x5xi32> |
| 22 | %y = arith.subi %arg0, %arg0 : tensor<4x5xi32> |
Stephan Herhut | af016ba | 2019-04-08 12:53:59 | [diff] [blame] | 23 | // CHECK-NEXT: return %cst |
| 24 | return %y: tensor<4x5xi32> |
| 25 | } |
| 26 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 27 | // CHECK-LABEL: func @dim |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 28 | func.func @dim(%arg0: tensor<8x4xf32>) -> index { |
Chris Lattner | 80e884a | 2018-10-16 16:31:45 | [diff] [blame] | 29 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 30 | // CHECK: %c4 = arith.constant 4 : index |
| 31 | %c1 = arith.constant 1 : index |
Matthias Springer | c0a6318 | 2021-07-01 00:58:48 | [diff] [blame] | 32 | %0 = tensor.dim %arg0, %c1 : tensor<8x4xf32> |
Chris Lattner | 80e884a | 2018-10-16 16:31:45 | [diff] [blame] | 33 | |
| 34 | // CHECK-NEXT: return %c4 |
| 35 | return %0 : index |
| 36 | } |
| 37 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 38 | // CHECK-LABEL: func @test_commutative |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 39 | func.func @test_commutative(%arg0: i32) -> (i32, i32) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 40 | // CHECK: %c42_i32 = arith.constant 42 : i32 |
| 41 | %c42_i32 = arith.constant 42 : i32 |
| 42 | // CHECK-NEXT: %0 = arith.addi %arg0, %c42_i32 : i32 |
| 43 | %y = arith.addi %c42_i32, %arg0 : i32 |
Chris Lattner | 967d934 | 2018-10-26 05:04:35 | [diff] [blame] | 44 | |
| 45 | // This should not be swapped. |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 46 | // CHECK-NEXT: %1 = arith.subi %c42_i32, %arg0 : i32 |
| 47 | %z = arith.subi %c42_i32, %arg0 : i32 |
Chris Lattner | 967d934 | 2018-10-26 05:04:35 | [diff] [blame] | 48 | |
| 49 | // CHECK-NEXT: return %0, %1 |
| 50 | return %y, %z: i32, i32 |
Chris Lattner | 9e3b928 | 2018-10-12 00:21:55 | [diff] [blame] | 51 | } |
| 52 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 53 | // CHECK-LABEL: func @trivial_dce |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 54 | func.func @trivial_dce(%arg0: tensor<8x4xf32>) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 55 | %c1 = arith.constant 1 : index |
Matthias Springer | c0a6318 | 2021-07-01 00:58:48 | [diff] [blame] | 56 | %0 = tensor.dim %arg0, %c1 : tensor<8x4xf32> |
Chris Lattner | 7850258 | 2018-10-22 02:53:10 | [diff] [blame] | 57 | // CHECK-NEXT: return |
| 58 | return |
| 59 | } |
| 60 | |
Tres Popp | 2d2d696 | 2020-04-23 16:13:44 | [diff] [blame] | 61 | // CHECK-LABEL: func @load_dce |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 62 | func.func @load_dce(%arg0: index) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 63 | %c4 = arith.constant 4 : index |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 64 | %a = memref.alloc(%c4) : memref<?xf32> |
| 65 | %2 = memref.load %a[%arg0] : memref<?xf32> |
| 66 | memref.dealloc %a: memref<?xf32> |
Tres Popp | 2d2d696 | 2020-04-23 16:13:44 | [diff] [blame] | 67 | // CHECK-NEXT: return |
| 68 | return |
| 69 | } |
| 70 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 71 | // CHECK-LABEL: func @addi_zero |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 72 | func.func @addi_zero(%arg0: i32) -> i32 { |
Chris Lattner | a03051b | 2018-10-22 20:08:27 | [diff] [blame] | 73 | // CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 74 | %c0_i32 = arith.constant 0 : i32 |
| 75 | %y = arith.addi %c0_i32, %arg0 : i32 |
Chris Lattner | a03051b | 2018-10-22 20:08:27 | [diff] [blame] | 76 | return %y: i32 |
| 77 | } |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 78 | |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 79 | // CHECK-LABEL: func @addi_zero_index |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 80 | func.func @addi_zero_index(%arg0: index) -> index { |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 81 | // CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 82 | %c0_index = arith.constant 0 : index |
| 83 | %y = arith.addi %c0_index, %arg0 : index |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 84 | return %y: index |
| 85 | } |
| 86 | |
| 87 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 88 | // CHECK-LABEL: func @addi_zero_vector |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 89 | func.func @addi_zero_vector(%arg0: vector<4 x i32>) -> vector<4 x i32> { |
Lei Zhang | 582b076 | 2018-10-29 17:22:49 | [diff] [blame] | 90 | // CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 91 | %c0_v4i32 = arith.constant dense<0> : vector<4 x i32> |
| 92 | %y = arith.addi %c0_v4i32, %arg0 : vector<4 x i32> |
Lei Zhang | 582b076 | 2018-10-29 17:22:49 | [diff] [blame] | 93 | return %y: vector<4 x i32> |
| 94 | } |
| 95 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 96 | // CHECK-LABEL: func @addi_zero_tensor |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 97 | func.func @addi_zero_tensor(%arg0: tensor<4 x 5 x i32>) -> tensor<4 x 5 x i32> { |
Lei Zhang | 582b076 | 2018-10-29 17:22:49 | [diff] [blame] | 98 | // CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 99 | %c0_t45i32 = arith.constant dense<0> : tensor<4 x 5 x i32> |
| 100 | %y = arith.addi %arg0, %c0_t45i32 : tensor<4 x 5 x i32> |
Lei Zhang | 582b076 | 2018-10-29 17:22:49 | [diff] [blame] | 101 | return %y: tensor<4 x 5 x i32> |
| 102 | } |
| 103 | |
Lei Zhang | 311af4a | 2019-01-11 17:12:11 | [diff] [blame] | 104 | // CHECK-LABEL: func @muli_zero |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 105 | func.func @muli_zero(%arg0: i32) -> i32 { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 106 | // CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 |
| 107 | %c0_i32 = arith.constant 0 : i32 |
Lei Zhang | 311af4a | 2019-01-11 17:12:11 | [diff] [blame] | 108 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 109 | %y = arith.muli %c0_i32, %arg0 : i32 |
Lei Zhang | 311af4a | 2019-01-11 17:12:11 | [diff] [blame] | 110 | |
| 111 | // CHECK-NEXT: return %c0_i32 |
| 112 | return %y: i32 |
| 113 | } |
| 114 | |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 115 | // CHECK-LABEL: func @muli_zero_index |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 116 | func.func @muli_zero_index(%arg0: index) -> index { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 117 | // CHECK-NEXT: %[[CST:.*]] = arith.constant 0 : index |
| 118 | %c0_index = arith.constant 0 : index |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 119 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 120 | %y = arith.muli %c0_index, %arg0 : index |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 121 | |
| 122 | // CHECK-NEXT: return %[[CST]] |
| 123 | return %y: index |
| 124 | } |
| 125 | |
Lei Zhang | 311af4a | 2019-01-11 17:12:11 | [diff] [blame] | 126 | // CHECK-LABEL: func @muli_zero_vector |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 127 | func.func @muli_zero_vector(%arg0: vector<4 x i32>) -> vector<4 x i32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 128 | // CHECK-NEXT: %cst = arith.constant dense<0> : vector<4xi32> |
| 129 | %cst = arith.constant dense<0> : vector<4 x i32> |
Lei Zhang | 311af4a | 2019-01-11 17:12:11 | [diff] [blame] | 130 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 131 | %y = arith.muli %cst, %arg0 : vector<4 x i32> |
Lei Zhang | 311af4a | 2019-01-11 17:12:11 | [diff] [blame] | 132 | |
| 133 | // CHECK-NEXT: return %cst |
| 134 | return %y: vector<4 x i32> |
| 135 | } |
| 136 | |
| 137 | // CHECK-LABEL: func @muli_zero_tensor |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 138 | func.func @muli_zero_tensor(%arg0: tensor<4 x 5 x i32>) -> tensor<4 x 5 x i32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 139 | // CHECK-NEXT: %cst = arith.constant dense<0> : tensor<4x5xi32> |
| 140 | %cst = arith.constant dense<0> : tensor<4 x 5 x i32> |
Lei Zhang | 311af4a | 2019-01-11 17:12:11 | [diff] [blame] | 141 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 142 | %y = arith.muli %arg0, %cst : tensor<4 x 5 x i32> |
Lei Zhang | 311af4a | 2019-01-11 17:12:11 | [diff] [blame] | 143 | |
| 144 | // CHECK-NEXT: return %cst |
| 145 | return %y: tensor<4 x 5 x i32> |
| 146 | } |
| 147 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 148 | // CHECK-LABEL: func @muli_one |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 149 | func.func @muli_one(%arg0: i32) -> i32 { |
Lei Zhang | 60b5184 | 2018-10-26 18:28:06 | [diff] [blame] | 150 | // CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 151 | %c0_i32 = arith.constant 1 : i32 |
| 152 | %y = arith.muli %c0_i32, %arg0 : i32 |
Lei Zhang | 60b5184 | 2018-10-26 18:28:06 | [diff] [blame] | 153 | return %y: i32 |
| 154 | } |
| 155 | |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 156 | // CHECK-LABEL: func @muli_one_index |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 157 | func.func @muli_one_index(%arg0: index) -> index { |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 158 | // CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 159 | %c0_index = arith.constant 1 : index |
| 160 | %y = arith.muli %c0_index, %arg0 : index |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 161 | return %y: index |
| 162 | } |
| 163 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 164 | // CHECK-LABEL: func @muli_one_vector |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 165 | func.func @muli_one_vector(%arg0: vector<4 x i32>) -> vector<4 x i32> { |
Lei Zhang | 582b076 | 2018-10-29 17:22:49 | [diff] [blame] | 166 | // CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 167 | %c1_v4i32 = arith.constant dense<1> : vector<4 x i32> |
| 168 | %y = arith.muli %c1_v4i32, %arg0 : vector<4 x i32> |
Lei Zhang | 582b076 | 2018-10-29 17:22:49 | [diff] [blame] | 169 | return %y: vector<4 x i32> |
| 170 | } |
| 171 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 172 | // CHECK-LABEL: func @muli_one_tensor |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 173 | func.func @muli_one_tensor(%arg0: tensor<4 x 5 x i32>) -> tensor<4 x 5 x i32> { |
Lei Zhang | 582b076 | 2018-10-29 17:22:49 | [diff] [blame] | 174 | // CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 175 | %c1_t45i32 = arith.constant dense<1> : tensor<4 x 5 x i32> |
| 176 | %y = arith.muli %arg0, %c1_t45i32 : tensor<4 x 5 x i32> |
Lei Zhang | 582b076 | 2018-10-29 17:22:49 | [diff] [blame] | 177 | return %y: tensor<4 x 5 x i32> |
| 178 | } |
| 179 | |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 180 | //CHECK-LABEL: func @and_self |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 181 | func.func @and_self(%arg0: i32) -> i32 { |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 182 | //CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 183 | %1 = arith.andi %arg0, %arg0 : i32 |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 184 | return %1 : i32 |
| 185 | } |
| 186 | |
| 187 | //CHECK-LABEL: func @and_self_vector |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 188 | func.func @and_self_vector(%arg0: vector<4xi32>) -> vector<4xi32> { |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 189 | //CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 190 | %1 = arith.andi %arg0, %arg0 : vector<4xi32> |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 191 | return %1 : vector<4xi32> |
| 192 | } |
| 193 | |
| 194 | //CHECK-LABEL: func @and_self_tensor |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 195 | func.func @and_self_tensor(%arg0: tensor<4x5xi32>) -> tensor<4x5xi32> { |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 196 | //CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 197 | %1 = arith.andi %arg0, %arg0 : tensor<4x5xi32> |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 198 | return %1 : tensor<4x5xi32> |
| 199 | } |
| 200 | |
| 201 | //CHECK-LABEL: func @and_zero |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 202 | func.func @and_zero(%arg0: i32) -> i32 { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 203 | // CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 |
| 204 | %c0_i32 = arith.constant 0 : i32 |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 205 | // CHECK-NEXT: return %c0_i32 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 206 | %1 = arith.andi %arg0, %c0_i32 : i32 |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 207 | return %1 : i32 |
| 208 | } |
| 209 | |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 210 | //CHECK-LABEL: func @and_zero_index |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 211 | func.func @and_zero_index(%arg0: index) -> index { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 212 | // CHECK-NEXT: %[[CST:.*]] = arith.constant 0 : index |
| 213 | %c0_index = arith.constant 0 : index |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 214 | // CHECK-NEXT: return %[[CST]] |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 215 | %1 = arith.andi %arg0, %c0_index : index |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 216 | return %1 : index |
| 217 | } |
| 218 | |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 219 | //CHECK-LABEL: func @and_zero_vector |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 220 | func.func @and_zero_vector(%arg0: vector<4xi32>) -> vector<4xi32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 221 | // CHECK-NEXT: %cst = arith.constant dense<0> : vector<4xi32> |
| 222 | %cst = arith.constant dense<0> : vector<4xi32> |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 223 | // CHECK-NEXT: return %cst |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 224 | %1 = arith.andi %arg0, %cst : vector<4xi32> |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 225 | return %1 : vector<4xi32> |
| 226 | } |
| 227 | |
| 228 | //CHECK-LABEL: func @and_zero_tensor |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 229 | func.func @and_zero_tensor(%arg0: tensor<4x5xi32>) -> tensor<4x5xi32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 230 | // CHECK-NEXT: %cst = arith.constant dense<0> : tensor<4x5xi32> |
| 231 | %cst = arith.constant dense<0> : tensor<4x5xi32> |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 232 | // CHECK-NEXT: return %cst |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 233 | %1 = arith.andi %arg0, %cst : tensor<4x5xi32> |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 234 | return %1 : tensor<4x5xi32> |
| 235 | } |
| 236 | |
| 237 | //CHECK-LABEL: func @or_self |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 238 | func.func @or_self(%arg0: i32) -> i32 { |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 239 | //CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 240 | %1 = arith.ori %arg0, %arg0 : i32 |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 241 | return %1 : i32 |
| 242 | } |
| 243 | |
| 244 | //CHECK-LABEL: func @or_self_vector |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 245 | func.func @or_self_vector(%arg0: vector<4xi32>) -> vector<4xi32> { |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 246 | //CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 247 | %1 = arith.ori %arg0, %arg0 : vector<4xi32> |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 248 | return %1 : vector<4xi32> |
| 249 | } |
| 250 | |
| 251 | //CHECK-LABEL: func @or_self_tensor |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 252 | func.func @or_self_tensor(%arg0: tensor<4x5xi32>) -> tensor<4x5xi32> { |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 253 | //CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 254 | %1 = arith.ori %arg0, %arg0 : tensor<4x5xi32> |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 255 | return %1 : tensor<4x5xi32> |
| 256 | } |
| 257 | |
| 258 | //CHECK-LABEL: func @or_zero |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 259 | func.func @or_zero(%arg0: i32) -> i32 { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 260 | %c0_i32 = arith.constant 0 : i32 |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 261 | // CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 262 | %1 = arith.ori %arg0, %c0_i32 : i32 |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 263 | return %1 : i32 |
| 264 | } |
| 265 | |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 266 | //CHECK-LABEL: func @or_zero_index |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 267 | func.func @or_zero_index(%arg0: index) -> index { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 268 | %c0_index = arith.constant 0 : index |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 269 | // CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 270 | %1 = arith.ori %arg0, %c0_index : index |
Stephan Herhut | e04d4bf | 2019-11-11 10:33:49 | [diff] [blame] | 271 | return %1 : index |
| 272 | } |
| 273 | |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 274 | //CHECK-LABEL: func @or_zero_vector |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 275 | func.func @or_zero_vector(%arg0: vector<4xi32>) -> vector<4xi32> { |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 276 | // CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 277 | %cst = arith.constant dense<0> : vector<4xi32> |
| 278 | %1 = arith.ori %arg0, %cst : vector<4xi32> |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 279 | return %1 : vector<4xi32> |
| 280 | } |
| 281 | |
| 282 | //CHECK-LABEL: func @or_zero_tensor |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 283 | func.func @or_zero_tensor(%arg0: tensor<4x5xi32>) -> tensor<4x5xi32> { |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 284 | // CHECK-NEXT: return %arg0 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 285 | %cst = arith.constant dense<0> : tensor<4x5xi32> |
| 286 | %1 = arith.ori %arg0, %cst : tensor<4x5xi32> |
Stephan Herhut | a8a5c069 | 2019-04-08 07:00:46 | [diff] [blame] | 287 | return %1 : tensor<4x5xi32> |
| 288 | } |
| 289 | |
Uday Bondhugula | 1e39d32 | 2021-10-06 04:39:56 | [diff] [blame] | 290 | // CHECK-LABEL: func @or_all_ones |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 291 | func.func @or_all_ones(%arg0: i1, %arg1: i4) -> (i1, i4) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 292 | // CHECK-DAG: %c-1_i4 = arith.constant -1 : i4 |
| 293 | // CHECK-DAG: %true = arith.constant true |
| 294 | %c1_i1 = arith.constant 1 : i1 |
| 295 | %c15 = arith.constant 15 : i4 |
Uday Bondhugula | 1e39d32 | 2021-10-06 04:39:56 | [diff] [blame] | 296 | // CHECK-NEXT: return %true |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 297 | %1 = arith.ori %arg0, %c1_i1 : i1 |
| 298 | %2 = arith.ori %arg1, %c15 : i4 |
Uday Bondhugula | 1e39d32 | 2021-10-06 04:39:56 | [diff] [blame] | 299 | return %1, %2 : i1, i4 |
| 300 | } |
| 301 | |
Stephan Herhut | af016ba | 2019-04-08 12:53:59 | [diff] [blame] | 302 | //CHECK-LABEL: func @xor_self |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 303 | func.func @xor_self(%arg0: i32) -> i32 { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 304 | //CHECK-NEXT: %c0_i32 = arith.constant 0 |
| 305 | %1 = arith.xori %arg0, %arg0 : i32 |
Stephan Herhut | af016ba | 2019-04-08 12:53:59 | [diff] [blame] | 306 | //CHECK-NEXT: return %c0_i32 |
| 307 | return %1 : i32 |
| 308 | } |
| 309 | |
| 310 | //CHECK-LABEL: func @xor_self_vector |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 311 | func.func @xor_self_vector(%arg0: vector<4xi32>) -> vector<4xi32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 312 | //CHECK-NEXT: %cst = arith.constant dense<0> : vector<4xi32> |
| 313 | %1 = arith.xori %arg0, %arg0 : vector<4xi32> |
Stephan Herhut | af016ba | 2019-04-08 12:53:59 | [diff] [blame] | 314 | //CHECK-NEXT: return %cst |
| 315 | return %1 : vector<4xi32> |
| 316 | } |
| 317 | |
| 318 | //CHECK-LABEL: func @xor_self_tensor |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 319 | func.func @xor_self_tensor(%arg0: tensor<4x5xi32>) -> tensor<4x5xi32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 320 | //CHECK-NEXT: %cst = arith.constant dense<0> : tensor<4x5xi32> |
| 321 | %1 = arith.xori %arg0, %arg0 : tensor<4x5xi32> |
Stephan Herhut | af016ba | 2019-04-08 12:53:59 | [diff] [blame] | 322 | //CHECK-NEXT: return %cst |
| 323 | return %1 : tensor<4x5xi32> |
| 324 | } |
| 325 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 326 | // CHECK-LABEL: func @memref_cast_folding |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 327 | func.func @memref_cast_folding(%arg0: memref<4 x f32>, %arg1: f32) -> (f32, f32) { |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 328 | %0 = memref.cast %arg0 : memref<4xf32> to memref<?xf32> |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 329 | // CHECK-NEXT: %c0 = arith.constant 0 : index |
| 330 | %c0 = arith.constant 0 : index |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 331 | %dim = memref.dim %0, %c0 : memref<? x f32> |
Uday Bondhugula | 1e6a93b | 2019-09-14 01:18:21 | [diff] [blame] | 332 | |
Uday Bondhugula | bd7de6d | 2019-09-17 18:49:14 | [diff] [blame] | 333 | // CHECK-NEXT: affine.load %arg0[3] |
Tres Popp | f66c876 | 2020-04-27 14:40:00 | [diff] [blame] | 334 | %1 = affine.load %0[%dim - 1] : memref<?xf32> |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 335 | |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 336 | // CHECK-NEXT: memref.store %arg1, %arg0[%c0] : memref<4xf32> |
| 337 | memref.store %arg1, %0[%c0] : memref<?xf32> |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 338 | |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 339 | // CHECK-NEXT: %{{.*}} = memref.load %arg0[%c0] : memref<4xf32> |
| 340 | %2 = memref.load %0[%c0] : memref<?xf32> |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 341 | |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 342 | // CHECK-NEXT: memref.dealloc %arg0 : memref<4xf32> |
| 343 | memref.dealloc %0: memref<?xf32> |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 344 | |
Uday Bondhugula | 1e6a93b | 2019-09-14 01:18:21 | [diff] [blame] | 345 | // CHECK-NEXT: return %{{.*}} |
Tres Popp | f66c876 | 2020-04-27 14:40:00 | [diff] [blame] | 346 | return %1, %2 : f32, f32 |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 347 | } |
| 348 | |
Alex Zinenko | 0c782c2 | 2020-11-06 09:20:08 | [diff] [blame] | 349 | // CHECK-LABEL: @fold_memref_cast_in_memref_cast |
| 350 | // CHECK-SAME: (%[[ARG0:.*]]: memref<42x42xf64>) |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 351 | func.func @fold_memref_cast_in_memref_cast(%0: memref<42x42xf64>) { |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 352 | // CHECK: %[[folded:.*]] = memref.cast %[[ARG0]] : memref<42x42xf64> to memref<?x?xf64> |
| 353 | %4 = memref.cast %0 : memref<42x42xf64> to memref<?x42xf64> |
| 354 | // CHECK-NOT: memref.cast |
| 355 | %5 = memref.cast %4 : memref<?x42xf64> to memref<?x?xf64> |
Alex Zinenko | 0c782c2 | 2020-11-06 09:20:08 | [diff] [blame] | 356 | // CHECK: "test.user"(%[[folded]]) |
| 357 | "test.user"(%5) : (memref<?x?xf64>) -> () |
| 358 | return |
| 359 | } |
| 360 | |
| 361 | // CHECK-LABEL: @fold_memref_cast_chain |
| 362 | // CHECK-SAME: (%[[ARG0:.*]]: memref<42x42xf64>) |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 363 | func.func @fold_memref_cast_chain(%0: memref<42x42xf64>) { |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 364 | // CHECK-NOT: memref.cast |
| 365 | %4 = memref.cast %0 : memref<42x42xf64> to memref<?x42xf64> |
| 366 | %5 = memref.cast %4 : memref<?x42xf64> to memref<42x42xf64> |
Alex Zinenko | 0c782c2 | 2020-11-06 09:20:08 | [diff] [blame] | 367 | // CHECK: "test.user"(%[[ARG0]]) |
| 368 | "test.user"(%5) : (memref<42x42xf64>) -> () |
| 369 | return |
| 370 | } |
| 371 | |
River Riddle | ada685f | 2019-01-16 19:40:37 | [diff] [blame] | 372 | // CHECK-LABEL: func @dead_alloc_fold |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 373 | func.func @dead_alloc_fold() { |
River Riddle | ada685f | 2019-01-16 19:40:37 | [diff] [blame] | 374 | // CHECK-NEXT: return |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 375 | %c4 = arith.constant 4 : index |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 376 | %a = memref.alloc(%c4) : memref<?xf32> |
River Riddle | ada685f | 2019-01-16 19:40:37 | [diff] [blame] | 377 | return |
| 378 | } |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 379 | |
River Riddle | 5843e5a | 2019-01-16 20:39:03 | [diff] [blame] | 380 | // CHECK-LABEL: func @dead_dealloc_fold |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 381 | func.func @dead_dealloc_fold() { |
River Riddle | 5843e5a | 2019-01-16 20:39:03 | [diff] [blame] | 382 | // CHECK-NEXT: return |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 383 | %a = memref.alloc() : memref<4xf32> |
| 384 | memref.dealloc %a: memref<4xf32> |
River Riddle | 5843e5a | 2019-01-16 20:39:03 | [diff] [blame] | 385 | return |
| 386 | } |
| 387 | |
| 388 | // CHECK-LABEL: func @dead_dealloc_fold_multi_use |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 389 | func.func @dead_dealloc_fold_multi_use(%cond : i1) { |
Mehdi Amini | a506279 | 2024-06-14 20:38:56 | [diff] [blame] | 390 | // CHECK-NOT: alloc |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 391 | %a = memref.alloc() : memref<4xf32> |
Mehdi Amini | a506279 | 2024-06-14 20:38:56 | [diff] [blame] | 392 | // CHECK: cond_br |
River Riddle | ace0160 | 2022-02-04 04:59:43 | [diff] [blame] | 393 | cf.cond_br %cond, ^bb1, ^bb2 |
River Riddle | 5843e5a | 2019-01-16 20:39:03 | [diff] [blame] | 394 | |
River Riddle | 5843e5a | 2019-01-16 20:39:03 | [diff] [blame] | 395 | ^bb1: |
Mehdi Amini | a506279 | 2024-06-14 20:38:56 | [diff] [blame] | 396 | // CHECK-NOT: alloc |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 397 | memref.dealloc %a: memref<4xf32> |
Mehdi Amini | a506279 | 2024-06-14 20:38:56 | [diff] [blame] | 398 | // CHECK: return |
River Riddle | 5843e5a | 2019-01-16 20:39:03 | [diff] [blame] | 399 | return |
| 400 | |
River Riddle | 5843e5a | 2019-01-16 20:39:03 | [diff] [blame] | 401 | ^bb2: |
Mehdi Amini | a506279 | 2024-06-14 20:38:56 | [diff] [blame] | 402 | // CHECK-NOT: alloc |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 403 | memref.dealloc %a: memref<4xf32> |
Mehdi Amini | a506279 | 2024-06-14 20:38:56 | [diff] [blame] | 404 | // CHECK: return |
River Riddle | 5843e5a | 2019-01-16 20:39:03 | [diff] [blame] | 405 | return |
| 406 | } |
| 407 | |
Butygin | f22d381 | 2021-04-10 16:38:11 | [diff] [blame] | 408 | // CHECK-LABEL: func @write_only_alloc_fold |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 409 | func.func @write_only_alloc_fold(%v: f32) { |
Butygin | f22d381 | 2021-04-10 16:38:11 | [diff] [blame] | 410 | // CHECK-NEXT: return |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 411 | %c0 = arith.constant 0 : index |
| 412 | %c4 = arith.constant 4 : index |
Butygin | f22d381 | 2021-04-10 16:38:11 | [diff] [blame] | 413 | %a = memref.alloc(%c4) : memref<?xf32> |
| 414 | memref.store %v, %a[%c0] : memref<?xf32> |
| 415 | memref.dealloc %a: memref<?xf32> |
| 416 | return |
| 417 | } |
| 418 | |
| 419 | // CHECK-LABEL: func @write_only_alloca_fold |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 420 | func.func @write_only_alloca_fold(%v: f32) { |
Butygin | f22d381 | 2021-04-10 16:38:11 | [diff] [blame] | 421 | // CHECK-NEXT: return |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 422 | %c0 = arith.constant 0 : index |
| 423 | %c4 = arith.constant 4 : index |
Butygin | f22d381 | 2021-04-10 16:38:11 | [diff] [blame] | 424 | %a = memref.alloca(%c4) : memref<?xf32> |
| 425 | memref.store %v, %a[%c0] : memref<?xf32> |
| 426 | return |
| 427 | } |
| 428 | |
River Riddle | a32f0dc | 2019-10-30 18:18:51 | [diff] [blame] | 429 | // CHECK-LABEL: func @dead_block_elim |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 430 | func.func @dead_block_elim() { |
Christian Sigg | 06ddb79 | 2020-04-08 06:59:59 | [diff] [blame] | 431 | // CHECK-NOT: ^bb |
Joshua Cao | 7d055af | 2024-02-06 06:59:03 | [diff] [blame] | 432 | builtin.module { |
| 433 | func.func @nested() { |
| 434 | return |
River Riddle | a32f0dc | 2019-10-30 18:18:51 | [diff] [blame] | 435 | |
Joshua Cao | 7d055af | 2024-02-06 06:59:03 | [diff] [blame] | 436 | ^bb1: |
| 437 | return |
| 438 | } |
River Riddle | a32f0dc | 2019-10-30 18:18:51 | [diff] [blame] | 439 | } |
| 440 | return |
River Riddle | a32f0dc | 2019-10-30 18:18:51 | [diff] [blame] | 441 | } |
| 442 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 443 | // CHECK-LABEL: func @dyn_shape_fold(%arg0: index, %arg1: index) |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 444 | func.func @dyn_shape_fold(%L : index, %M : index) -> (memref<4 x ? x 8 x ? x ? x f32>, memref<? x ? x i32>, memref<? x ? x f32>, memref<4 x ? x 8 x ? x ? x f32>) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 445 | // CHECK: %c0 = arith.constant 0 : index |
| 446 | %zero = arith.constant 0 : index |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 447 | // The constants below disappear after they propagate into shapes. |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 448 | %nine = arith.constant 9 : index |
| 449 | %N = arith.constant 1024 : index |
| 450 | %K = arith.constant 512 : index |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 451 | |
Butygin | f22d381 | 2021-04-10 16:38:11 | [diff] [blame] | 452 | // CHECK: memref.alloc(%arg0) : memref<?x1024xf32> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 453 | %a = memref.alloc(%L, %N) : memref<? x ? x f32> |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 454 | |
Butygin | f22d381 | 2021-04-10 16:38:11 | [diff] [blame] | 455 | // CHECK: memref.alloc(%arg1) : memref<4x1024x8x512x?xf32> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 456 | %b = memref.alloc(%N, %K, %M) : memref<4 x ? x 8 x ? x ? x f32> |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 457 | |
Butygin | f22d381 | 2021-04-10 16:38:11 | [diff] [blame] | 458 | // CHECK: memref.alloc() : memref<512x1024xi32> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 459 | %c = memref.alloc(%K, %N) : memref<? x ? x i32> |
Uday Bondhugula | 0328217 | 2018-11-20 21:39:35 | [diff] [blame] | 460 | |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 461 | // CHECK: memref.alloc() : memref<9x9xf32> |
| 462 | %d = memref.alloc(%nine, %nine) : memref<? x ? x f32> |
Uday Bondhugula | 7023f4b | 2020-03-22 15:50:21 | [diff] [blame] | 463 | |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 464 | // CHECK: memref.alloca(%arg1) : memref<4x1024x8x512x?xf32> |
| 465 | %e = memref.alloca(%N, %K, %M) : memref<4 x ? x 8 x ? x ? x f32> |
Uday Bondhugula | 7023f4b | 2020-03-22 15:50:21 | [diff] [blame] | 466 | |
River Riddle | 89bc449 | 2019-07-09 17:40:29 | [diff] [blame] | 467 | // CHECK: affine.for |
River Riddle | 832567b | 2019-03-25 17:14:34 | [diff] [blame] | 468 | affine.for %i = 0 to %L { |
River Riddle | 89bc449 | 2019-07-09 17:40:29 | [diff] [blame] | 469 | // CHECK-NEXT: affine.for |
River Riddle | 832567b | 2019-03-25 17:14:34 | [diff] [blame] | 470 | affine.for %j = 0 to 10 { |
Nicolas Vasilache | 435debe | 2022-09-30 15:20:29 | [diff] [blame] | 471 | // CHECK-NEXT: memref.load %{{.*}}[%arg2, %arg3] : memref<?x1024xf32> |
| 472 | // CHECK-NEXT: memref.store %{{.*}}, %{{.*}}[%c0, %c0, %arg2, %arg3, %c0] : memref<4x1024x8x512x?xf32> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 473 | %v = memref.load %a[%i, %j] : memref<?x?xf32> |
| 474 | memref.store %v, %b[%zero, %zero, %i, %j, %zero] : memref<4x?x8x?x?xf32> |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
Butygin | f22d381 | 2021-04-10 16:38:11 | [diff] [blame] | 478 | return %b, %c, %d, %e : memref<4 x ? x 8 x ? x ? x f32>, memref<? x ? x i32>, memref<? x ? x f32>, memref<4 x ? x 8 x ? x ? x f32> |
Chris Lattner | 301f83f | 2018-10-23 17:12:00 | [diff] [blame] | 479 | } |
Chris Lattner | bd01f95 | 2018-10-24 16:22:48 | [diff] [blame] | 480 | |
Nicolas Vasilache | 8b78c50 | 2020-05-15 17:45:06 | [diff] [blame] | 481 | // CHECK-LABEL: func @dim_op_fold( |
| 482 | // CHECK-SAME: %[[ARG0:[a-z0-9]*]]: index |
| 483 | // CHECK-SAME: %[[ARG1:[a-z0-9]*]]: index |
| 484 | // CHECK-SAME: %[[ARG2:[a-z0-9]*]]: index |
| 485 | // CHECK-SAME: %[[BUF:[a-z0-9]*]]: memref<?xi8> |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 486 | func.func @dim_op_fold(%arg0: index, %arg1: index, %arg2: index, %BUF: memref<?xi8>, %M : index, %N : index, %K : index) { |
Uday Bondhugula | 3ade6a7 | 2019-12-06 13:59:06 | [diff] [blame] | 487 | // CHECK-SAME: [[M:arg[0-9]+]]: index |
| 488 | // CHECK-SAME: [[N:arg[0-9]+]]: index |
| 489 | // CHECK-SAME: [[K:arg[0-9]+]]: index |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 490 | %c0 = arith.constant 0 : index |
| 491 | %c1 = arith.constant 1 : index |
| 492 | %c2 = arith.constant 2 : index |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 493 | %0 = memref.alloc(%arg0, %arg1) : memref<?x?xf32> |
| 494 | %1 = memref.alloc(%arg1, %arg2) : memref<?x8x?xf32> |
| 495 | %2 = memref.dim %1, %c2 : memref<?x8x?xf32> |
Uday Bondhugula | 3ade6a7 | 2019-12-06 13:59:06 | [diff] [blame] | 496 | affine.for %arg3 = 0 to %2 { |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 497 | %3 = memref.alloc(%arg0) : memref<?xi8> |
| 498 | %ub = memref.dim %3, %c0 : memref<?xi8> |
Uday Bondhugula | 3ade6a7 | 2019-12-06 13:59:06 | [diff] [blame] | 499 | affine.for %arg4 = 0 to %ub { |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 500 | %s = memref.dim %0, %c0 : memref<?x?xf32> |
| 501 | %v = memref.view %3[%c0][%arg4, %s] : memref<?xi8> to memref<?x?xf32> |
Alex Zinenko | f3fae03 | 2022-09-16 13:36:40 | [diff] [blame] | 502 | %sv = memref.subview %0[%c0, %c0][%s,%arg4][%c1,%c1] : memref<?x?xf32> to memref<?x?xf32, strided<[?, ?], offset: ?>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 503 | %l = memref.dim %v, %c1 : memref<?x?xf32> |
Alex Zinenko | f3fae03 | 2022-09-16 13:36:40 | [diff] [blame] | 504 | %u = memref.dim %sv, %c0 : memref<?x?xf32, strided<[?, ?], offset: ?>> |
Uday Bondhugula | 3ade6a7 | 2019-12-06 13:59:06 | [diff] [blame] | 505 | affine.for %arg5 = %l to %u { |
| 506 | "foo"() : () -> () |
| 507 | } |
Matthias Springer | 6dc8de7 | 2024-06-23 17:05:00 | [diff] [blame] | 508 | %sv2 = memref.subview %0[0, 0][17, %arg4][1, 1] : memref<?x?xf32> to memref<17x?xf32, strided<[?, 1]>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 509 | %l2 = memref.dim %v, %c1 : memref<?x?xf32> |
Matthias Springer | 6dc8de7 | 2024-06-23 17:05:00 | [diff] [blame] | 510 | %u2 = memref.dim %sv2, %c1 : memref<17x?xf32, strided<[?, 1]>> |
Nicolas Vasilache | 8b78c50 | 2020-05-15 17:45:06 | [diff] [blame] | 511 | scf.for %arg5 = %l2 to %u2 step %c1 { |
| 512 | "foo"() : () -> () |
| 513 | } |
Uday Bondhugula | 3ade6a7 | 2019-12-06 13:59:06 | [diff] [blame] | 514 | } |
| 515 | } |
Nicolas Vasilache | 8b78c50 | 2020-05-15 17:45:06 | [diff] [blame] | 516 | // CHECK: affine.for %[[I:.*]] = 0 to %[[ARG2]] { |
| 517 | // CHECK-NEXT: affine.for %[[J:.*]] = 0 to %[[ARG0]] { |
| 518 | // CHECK-NEXT: affine.for %[[K:.*]] = %[[ARG0]] to %[[ARG0]] { |
| 519 | // CHECK-NEXT: "foo"() : () -> () |
| 520 | // CHECK-NEXT: } |
| 521 | // CHECK-NEXT: scf.for %[[KK:.*]] = %[[ARG0]] to %[[J]] step %{{.*}} { |
Uday Bondhugula | 3ade6a7 | 2019-12-06 13:59:06 | [diff] [blame] | 522 | // CHECK-NEXT: "foo"() : () -> () |
| 523 | // CHECK-NEXT: } |
| 524 | // CHECK-NEXT: } |
| 525 | // CHECK-NEXT: } |
| 526 | |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 527 | %A = memref.view %BUF[%c0][%M, %K] : memref<?xi8> to memref<?x?xf32> |
| 528 | %B = memref.view %BUF[%c0][%K, %N] : memref<?xi8> to memref<?x?xf32> |
| 529 | %C = memref.view %BUF[%c0][%M, %N] : memref<?xi8> to memref<?x?xf32> |
Uday Bondhugula | 3ade6a7 | 2019-12-06 13:59:06 | [diff] [blame] | 530 | |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 531 | %M_ = memref.dim %A, %c0 : memref<?x?xf32> |
| 532 | %K_ = memref.dim %A, %c1 : memref<?x?xf32> |
| 533 | %N_ = memref.dim %C, %c1 : memref<?x?xf32> |
Alex Zinenko | 60f443b | 2020-05-13 10:12:30 | [diff] [blame] | 534 | scf.for %i = %c0 to %M_ step %c1 { |
| 535 | scf.for %j = %c0 to %N_ step %c1 { |
| 536 | scf.for %k = %c0 to %K_ step %c1 { |
Uday Bondhugula | 3ade6a7 | 2019-12-06 13:59:06 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | } |
River Riddle | 0ddba0b | 2020-03-12 21:06:41 | [diff] [blame] | 540 | // CHECK-NEXT: return |
Uday Bondhugula | 3ade6a7 | 2019-12-06 13:59:06 | [diff] [blame] | 541 | return |
| 542 | } |
| 543 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 544 | // CHECK-LABEL: func @merge_constants |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 545 | func.func @merge_constants() -> (index, index) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 546 | // CHECK-NEXT: %c42 = arith.constant 42 : index |
| 547 | %0 = arith.constant 42 : index |
| 548 | %1 = arith.constant 42 : index |
Chris Lattner | bd01f95 | 2018-10-24 16:22:48 | [diff] [blame] | 549 | // CHECK-NEXT: return %c42, %c42 |
| 550 | return %0, %1: index, index |
| 551 | } |
| 552 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 553 | // CHECK-LABEL: func @hoist_constant |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 554 | func.func @hoist_constant(%arg0: memref<8xi32>) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 555 | // CHECK-NEXT: %c42_i32 = arith.constant 42 : i32 |
River Riddle | 89bc449 | 2019-07-09 17:40:29 | [diff] [blame] | 556 | // CHECK-NEXT: affine.for %arg1 = 0 to 8 { |
| 557 | affine.for %arg1 = 0 to 8 { |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 558 | // CHECK-NEXT: memref.store %c42_i32, %arg0[%arg1] |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 559 | %c42_i32 = arith.constant 42 : i32 |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 560 | memref.store %c42_i32, %arg0[%arg1] : memref<8xi32> |
Chris Lattner | bd01f95 | 2018-10-24 16:22:48 | [diff] [blame] | 561 | } |
| 562 | return |
| 563 | } |
Chris Lattner | 967d934 | 2018-10-26 05:04:35 | [diff] [blame] | 564 | |
Chris Lattner | bbf362b | 2019-01-02 18:20:00 | [diff] [blame] | 565 | // CHECK-LABEL: func @const_fold_propagate |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 566 | func.func @const_fold_propagate() -> memref<?x?xf32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 567 | %VT_i = arith.constant 512 : index |
Chris Lattner | 967d934 | 2018-10-26 05:04:35 | [diff] [blame] | 568 | |
River Riddle | 4268e4f | 2020-01-13 21:12:37 | [diff] [blame] | 569 | %VT_i_s = affine.apply affine_map<(d0) -> (d0 floordiv 8)> (%VT_i) |
| 570 | %VT_k_l = affine.apply affine_map<(d0) -> (d0 floordiv 16)> (%VT_i) |
Chris Lattner | 967d934 | 2018-10-26 05:04:35 | [diff] [blame] | 571 | |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 572 | // CHECK: = memref.alloc() : memref<64x32xf32> |
| 573 | %Av = memref.alloc(%VT_i_s, %VT_k_l) : memref<?x?xf32> |
Chris Lattner | 967d934 | 2018-10-26 05:04:35 | [diff] [blame] | 574 | return %Av : memref<?x?xf32> |
Chris Lattner | 7983bbc | 2019-01-04 15:23:28 | [diff] [blame] | 575 | } |
River Riddle | ed26dd0 | 2019-01-14 21:23:18 | [diff] [blame] | 576 | |
River Riddle | 9941112 | 2019-01-30 02:08:28 | [diff] [blame] | 577 | // CHECK-LABEL: func @indirect_call_folding |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 578 | func.func @indirect_target() { |
River Riddle | 9941112 | 2019-01-30 02:08:28 | [diff] [blame] | 579 | return |
| 580 | } |
| 581 | |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 582 | func.func @indirect_call_folding() { |
River Riddle | 9941112 | 2019-01-30 02:08:28 | [diff] [blame] | 583 | // CHECK-NEXT: call @indirect_target() : () -> () |
| 584 | // CHECK-NEXT: return |
| 585 | %indirect_fn = constant @indirect_target : () -> () |
| 586 | call_indirect %indirect_fn() : () -> () |
| 587 | return |
| 588 | } |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 589 | |
Stephan Herhut | 9c7bceb | 2019-11-15 11:59:57 | [diff] [blame] | 590 | // |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 591 | // IMPORTANT NOTE: the operations in this test are exactly those produced by |
River Riddle | 4268e4f | 2020-01-13 21:12:37 | [diff] [blame] | 592 | // lowering affine.apply affine_map<(i) -> (i mod 42)> to standard operations. Please only |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 593 | // change these operations together with the affine lowering pass tests. |
Stephan Herhut | 9c7bceb | 2019-11-15 11:59:57 | [diff] [blame] | 594 | // |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 595 | // CHECK-LABEL: @lowered_affine_mod |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 596 | func.func @lowered_affine_mod() -> (index, index) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 597 | // CHECK-DAG: {{.*}} = arith.constant 1 : index |
| 598 | // CHECK-DAG: {{.*}} = arith.constant 41 : index |
| 599 | %c-43 = arith.constant -43 : index |
| 600 | %c42 = arith.constant 42 : index |
| 601 | %0 = arith.remsi %c-43, %c42 : index |
| 602 | %c0 = arith.constant 0 : index |
| 603 | %1 = arith.cmpi slt, %0, %c0 : index |
| 604 | %2 = arith.addi %0, %c42 : index |
River Riddle | dec8af7 | 2022-01-31 20:44:35 | [diff] [blame] | 605 | %3 = arith.select %1, %2, %0 : index |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 606 | %c43 = arith.constant 43 : index |
| 607 | %c42_0 = arith.constant 42 : index |
| 608 | %4 = arith.remsi %c43, %c42_0 : index |
| 609 | %c0_1 = arith.constant 0 : index |
| 610 | %5 = arith.cmpi slt, %4, %c0_1 : index |
| 611 | %6 = arith.addi %4, %c42_0 : index |
River Riddle | dec8af7 | 2022-01-31 20:44:35 | [diff] [blame] | 612 | %7 = arith.select %5, %6, %4 : index |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 613 | return %3, %7 : index, index |
| 614 | } |
| 615 | |
Stephan Herhut | 9c7bceb | 2019-11-15 11:59:57 | [diff] [blame] | 616 | // |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 617 | // IMPORTANT NOTE: the operations in this test are exactly those produced by |
River Riddle | 4268e4f | 2020-01-13 21:12:37 | [diff] [blame] | 618 | // lowering affine.apply affine_map<(i) -> (i mod 42)> to standard operations. Please only |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 619 | // change these operations together with the affine lowering pass tests. |
Stephan Herhut | 9c7bceb | 2019-11-15 11:59:57 | [diff] [blame] | 620 | // |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 621 | // CHECK-LABEL: func @lowered_affine_floordiv |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 622 | func.func @lowered_affine_floordiv() -> (index, index) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 623 | // CHECK-DAG: %c1 = arith.constant 1 : index |
| 624 | // CHECK-DAG: %c-2 = arith.constant -2 : index |
| 625 | %c-43 = arith.constant -43 : index |
| 626 | %c42 = arith.constant 42 : index |
| 627 | %c0 = arith.constant 0 : index |
| 628 | %c-1 = arith.constant -1 : index |
| 629 | %0 = arith.cmpi slt, %c-43, %c0 : index |
| 630 | %1 = arith.subi %c-1, %c-43 : index |
River Riddle | dec8af7 | 2022-01-31 20:44:35 | [diff] [blame] | 631 | %2 = arith.select %0, %1, %c-43 : index |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 632 | %3 = arith.divsi %2, %c42 : index |
| 633 | %4 = arith.subi %c-1, %3 : index |
River Riddle | dec8af7 | 2022-01-31 20:44:35 | [diff] [blame] | 634 | %5 = arith.select %0, %4, %3 : index |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 635 | %c43 = arith.constant 43 : index |
| 636 | %c42_0 = arith.constant 42 : index |
| 637 | %c0_1 = arith.constant 0 : index |
| 638 | %c-1_2 = arith.constant -1 : index |
| 639 | %6 = arith.cmpi slt, %c43, %c0_1 : index |
| 640 | %7 = arith.subi %c-1_2, %c43 : index |
River Riddle | dec8af7 | 2022-01-31 20:44:35 | [diff] [blame] | 641 | %8 = arith.select %6, %7, %c43 : index |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 642 | %9 = arith.divsi %8, %c42_0 : index |
| 643 | %10 = arith.subi %c-1_2, %9 : index |
River Riddle | dec8af7 | 2022-01-31 20:44:35 | [diff] [blame] | 644 | %11 = arith.select %6, %10, %9 : index |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 645 | return %5, %11 : index, index |
| 646 | } |
| 647 | |
Stephan Herhut | 9c7bceb | 2019-11-15 11:59:57 | [diff] [blame] | 648 | // |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 649 | // IMPORTANT NOTE: the operations in this test are exactly those produced by |
River Riddle | 4268e4f | 2020-01-13 21:12:37 | [diff] [blame] | 650 | // lowering affine.apply affine_map<(i) -> (i mod 42)> to standard operations. Please only |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 651 | // change these operations together with the affine lowering pass tests. |
Stephan Herhut | 9c7bceb | 2019-11-15 11:59:57 | [diff] [blame] | 652 | // |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 653 | // CHECK-LABEL: func @lowered_affine_ceildiv |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 654 | func.func @lowered_affine_ceildiv() -> (index, index) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 655 | // CHECK-DAG: %c-1 = arith.constant -1 : index |
| 656 | %c-43 = arith.constant -43 : index |
| 657 | %c42 = arith.constant 42 : index |
| 658 | %c0 = arith.constant 0 : index |
| 659 | %c1 = arith.constant 1 : index |
| 660 | %0 = arith.cmpi sle, %c-43, %c0 : index |
| 661 | %1 = arith.subi %c0, %c-43 : index |
| 662 | %2 = arith.subi %c-43, %c1 : index |
River Riddle | dec8af7 | 2022-01-31 20:44:35 | [diff] [blame] | 663 | %3 = arith.select %0, %1, %2 : index |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 664 | %4 = arith.divsi %3, %c42 : index |
| 665 | %5 = arith.subi %c0, %4 : index |
| 666 | %6 = arith.addi %4, %c1 : index |
River Riddle | dec8af7 | 2022-01-31 20:44:35 | [diff] [blame] | 667 | %7 = arith.select %0, %5, %6 : index |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 668 | // CHECK-DAG: %c2 = arith.constant 2 : index |
| 669 | %c43 = arith.constant 43 : index |
| 670 | %c42_0 = arith.constant 42 : index |
| 671 | %c0_1 = arith.constant 0 : index |
| 672 | %c1_2 = arith.constant 1 : index |
| 673 | %8 = arith.cmpi sle, %c43, %c0_1 : index |
| 674 | %9 = arith.subi %c0_1, %c43 : index |
| 675 | %10 = arith.subi %c43, %c1_2 : index |
River Riddle | dec8af7 | 2022-01-31 20:44:35 | [diff] [blame] | 676 | %11 = arith.select %8, %9, %10 : index |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 677 | %12 = arith.divsi %11, %c42_0 : index |
| 678 | %13 = arith.subi %c0_1, %12 : index |
| 679 | %14 = arith.addi %12, %c1_2 : index |
River Riddle | dec8af7 | 2022-01-31 20:44:35 | [diff] [blame] | 680 | %15 = arith.select %8, %13, %14 : index |
Chris Lattner | a004da0 | 2021-05-24 22:45:58 | [diff] [blame] | 681 | |
| 682 | // CHECK-NEXT: return %c-1, %c2 |
River Riddle | a886625 | 2019-02-07 16:26:31 | [diff] [blame] | 683 | return %7, %15 : index, index |
| 684 | } |
Smit Hinsu | c9b0540 | 2019-04-28 03:55:38 | [diff] [blame] | 685 | |
| 686 | // Checks that NOP casts are removed. |
| 687 | // CHECK-LABEL: cast_values |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 688 | func.func @cast_values(%arg0: memref<?xi32>) -> memref<2xi32> { |
Sean Silva | 129d6e5 | 2020-12-16 00:47:19 | [diff] [blame] | 689 | // NOP cast |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 690 | %1 = memref.cast %arg0 : memref<?xi32> to memref<?xi32> |
| 691 | // CHECK-NEXT: %[[RET:.*]] = memref.cast %arg0 : memref<?xi32> to memref<2xi32> |
| 692 | %3 = memref.cast %1 : memref<?xi32> to memref<2xi32> |
Sean Silva | 129d6e5 | 2020-12-16 00:47:19 | [diff] [blame] | 693 | // NOP cast |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 694 | %5 = memref.cast %3 : memref<2xi32> to memref<2xi32> |
Sean Silva | 129d6e5 | 2020-12-16 00:47:19 | [diff] [blame] | 695 | // CHECK-NEXT: return %[[RET]] : memref<2xi32> |
| 696 | return %5 : memref<2xi32> |
Smit Hinsu | c9b0540 | 2019-04-28 03:55:38 | [diff] [blame] | 697 | } |
Andy Davis | 5fbdb67 | 2019-11-07 16:04:33 | [diff] [blame] | 698 | |
Stephan Herhut | 9c7bceb | 2019-11-15 11:59:57 | [diff] [blame] | 699 | // ----- |
| 700 | |
Andy Davis | 5fbdb67 | 2019-11-07 16:04:33 | [diff] [blame] | 701 | // CHECK-LABEL: func @view |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 702 | func.func @view(%arg0 : index) -> (f32, f32, f32, f32) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 703 | // CHECK: %[[C15:.*]] = arith.constant 15 : index |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 704 | // CHECK: %[[ALLOC_MEM:.*]] = memref.alloc() : memref<2048xi8> |
| 705 | %0 = memref.alloc() : memref<2048xi8> |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 706 | %c0 = arith.constant 0 : index |
| 707 | %c7 = arith.constant 7 : index |
| 708 | %c11 = arith.constant 11 : index |
| 709 | %c15 = arith.constant 15 : index |
Andy Davis | 5fbdb67 | 2019-11-07 16:04:33 | [diff] [blame] | 710 | |
Nicolas Vasilache | 6ed61a2 | 2020-05-11 16:09:18 | [diff] [blame] | 711 | // Test: fold constant sizes. |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 712 | // CHECK: memref.view %[[ALLOC_MEM]][%[[C15]]][] : memref<2048xi8> to memref<7x11xf32> |
| 713 | %1 = memref.view %0[%c15][%c7, %c11] : memref<2048xi8> to memref<?x?xf32> |
| 714 | %r0 = memref.load %1[%c0, %c0] : memref<?x?xf32> |
Andy Davis | 8f00b44 | 2019-11-07 18:19:54 | [diff] [blame] | 715 | |
Nicolas Vasilache | 6ed61a2 | 2020-05-11 16:09:18 | [diff] [blame] | 716 | // Test: fold one constant size. |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 717 | // CHECK: memref.view %[[ALLOC_MEM]][%[[C15]]][%arg0, %arg0] : memref<2048xi8> to memref<?x?x7xf32> |
| 718 | %2 = memref.view %0[%c15][%arg0, %arg0, %c7] : memref<2048xi8> to memref<?x?x?xf32> |
| 719 | %r1 = memref.load %2[%c0, %c0, %c0] : memref<?x?x?xf32> |
Andy Davis | 8f00b44 | 2019-11-07 18:19:54 | [diff] [blame] | 720 | |
Nicolas Vasilache | 6ed61a2 | 2020-05-11 16:09:18 | [diff] [blame] | 721 | // Test: preserve an existing static size. |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 722 | // CHECK: memref.view %[[ALLOC_MEM]][%[[C15]]][] : memref<2048xi8> to memref<7x4xf32> |
| 723 | %3 = memref.view %0[%c15][%c7] : memref<2048xi8> to memref<?x4xf32> |
| 724 | %r2 = memref.load %3[%c0, %c0] : memref<?x4xf32> |
Andy Davis | 5fbdb67 | 2019-11-07 16:04:33 | [diff] [blame] | 725 | |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 726 | // Test: folding static alloc and memref.cast into a view. |
klensy | a5985ca | 2024-06-14 15:16:02 | [diff] [blame] | 727 | // CHECK: memref.view %[[ALLOC_MEM]][%[[C15]]][] : memref<2048xi8> to memref<15x7xf32> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 728 | %4 = memref.cast %0 : memref<2048xi8> to memref<?xi8> |
| 729 | %5 = memref.view %4[%c15][%c15, %c7] : memref<?xi8> to memref<?x?xf32> |
| 730 | %r3 = memref.load %5[%c0, %c0] : memref<?x?xf32> |
Nicolas Vasilache | 6ed61a2 | 2020-05-11 16:09:18 | [diff] [blame] | 731 | return %r0, %r1, %r2, %r3 : f32, f32, f32, f32 |
Andy Davis | 5fbdb67 | 2019-11-07 16:04:33 | [diff] [blame] | 732 | } |
Andy Davis | a4669cd | 2019-11-14 20:22:28 | [diff] [blame] | 733 | |
Stephan Herhut | 9c7bceb | 2019-11-15 11:59:57 | [diff] [blame] | 734 | // ----- |
| 735 | |
Andy Davis | a4669cd | 2019-11-14 20:22:28 | [diff] [blame] | 736 | // CHECK-LABEL: func @subview |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 737 | // CHECK-SAME: %[[ARG0:.*]]: index, %[[ARG1:.*]]: index |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 738 | func.func @subview(%arg0 : index, %arg1 : index) -> (index, index) { |
Chris Lattner | b2f232b | 2021-03-20 00:57:47 | [diff] [blame] | 739 | // Folded but reappears after subview folding into dim. |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 740 | // CHECK-DAG: %[[C0:.*]] = arith.constant 0 : index |
| 741 | // CHECK-DAG: %[[C7:.*]] = arith.constant 7 : index |
| 742 | // CHECK-DAG: %[[C11:.*]] = arith.constant 11 : index |
| 743 | %c0 = arith.constant 0 : index |
| 744 | // CHECK-NOT: arith.constant 1 : index |
| 745 | %c1 = arith.constant 1 : index |
| 746 | // CHECK-NOT: arith.constant 2 : index |
| 747 | %c2 = arith.constant 2 : index |
Nicolas Vasilache | 63c0e72 | 2020-05-12 21:17:34 | [diff] [blame] | 748 | // Folded but reappears after subview folding into dim. |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 749 | %c7 = arith.constant 7 : index |
| 750 | %c11 = arith.constant 11 : index |
| 751 | // CHECK-NOT: arith.constant 15 : index |
| 752 | %c15 = arith.constant 15 : index |
Andy Davis | a4669cd | 2019-11-14 20:22:28 | [diff] [blame] | 753 | |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 754 | // CHECK: %[[ALLOC0:.*]] = memref.alloc() |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 755 | %0 = memref.alloc() : memref<128x96x64xf32, strided<[6144, 64, 1], offset: 0>> |
Andy Davis | a4669cd | 2019-11-14 20:22:28 | [diff] [blame] | 756 | |
| 757 | // Test: subview with constant base memref and constant operands is folded. |
Andy Davis | a6a2873 | 2019-11-18 23:00:34 | [diff] [blame] | 758 | // Note that the subview uses the base memrefs layout map because it used |
| 759 | // zero offset and unit stride arguments. |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 760 | // CHECK: memref.subview %[[ALLOC0]][0, 0, 0] [7, 11, 2] [1, 1, 1] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 761 | // CHECK-SAME: memref<128x96x64xf32, strided<[6144, 64, 1]>> |
| 762 | // CHECK-SAME: to memref<7x11x2xf32, strided<[6144, 64, 1]>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 763 | %1 = memref.subview %0[%c0, %c0, %c0] [%c7, %c11, %c2] [%c1, %c1, %c1] |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 764 | : memref<128x96x64xf32, strided<[6144, 64, 1], offset: 0>> to |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 765 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
| 766 | %v0 = memref.load %1[%c0, %c0, %c0] : memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Andy Davis | a4669cd | 2019-11-14 20:22:28 | [diff] [blame] | 767 | |
Nicolas Vasilache | 63c0e72 | 2020-05-12 21:17:34 | [diff] [blame] | 768 | // Test: subview with one dynamic operand can also be folded. |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 769 | // CHECK: memref.subview %[[ALLOC0]][0, %[[ARG0]], 0] [7, 11, 15] [1, 1, 1] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 770 | // CHECK-SAME: memref<128x96x64xf32, strided<[6144, 64, 1]>> |
| 771 | // CHECK-SAME: to memref<7x11x15xf32, strided<[6144, 64, 1], offset: ?>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 772 | %2 = memref.subview %0[%c0, %arg0, %c0] [%c7, %c11, %c15] [%c1, %c1, %c1] |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 773 | : memref<128x96x64xf32, strided<[6144, 64, 1], offset: 0>> to |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 774 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
| 775 | memref.store %v0, %2[%c0, %c0, %c0] : memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Andy Davis | a4669cd | 2019-11-14 20:22:28 | [diff] [blame] | 776 | |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 777 | // CHECK: %[[ALLOC1:.*]] = memref.alloc(%[[ARG0]]) |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 778 | %3 = memref.alloc(%arg0) : memref<?x16x4xf32, strided<[64, 4, 1], offset: 0>> |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 779 | // Test: subview with constant operands but dynamic base memref is folded as long as the strides and offset of the base memref are static. |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 780 | // CHECK: memref.subview %[[ALLOC1]][0, 0, 0] [7, 11, 2] [1, 1, 1] : |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 781 | // CHECK-SAME: memref<?x16x4xf32, strided<[64, 4, 1]>> |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 782 | // CHECK-SAME: to memref<7x11x2xf32, strided<[64, 4, 1]>> |
| 783 | %4 = memref.subview %3[%c0, %c0, %c0] [%c7, %c11, %c2] [%c1, %c1, %c1] |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 784 | : memref<?x16x4xf32, strided<[64, 4, 1], offset: 0>> to |
| 785 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
| 786 | memref.store %v0, %4[%c0, %c0, %c0] : memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Andy Davis | a4669cd | 2019-11-14 20:22:28 | [diff] [blame] | 787 | |
Uday Bondhugula | 3ade6a7 | 2019-12-06 13:59:06 | [diff] [blame] | 788 | // Test: subview offset operands are folded correctly w.r.t. base strides. |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 789 | // CHECK: memref.subview %[[ALLOC0]][1, 2, 7] [7, 11, 2] [1, 1, 1] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 790 | // CHECK-SAME: memref<128x96x64xf32, strided<[6144, 64, 1]>> to |
| 791 | // CHECK-SAME: memref<7x11x2xf32, strided<[6144, 64, 1], offset: 6279>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 792 | %5 = memref.subview %0[%c1, %c2, %c7] [%c7, %c11, %c2] [%c1, %c1, %c1] |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 793 | : memref<128x96x64xf32, strided<[6144, 64, 1], offset: 0>> to |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 794 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
| 795 | memref.store %v0, %5[%c0, %c0, %c0] : memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Andy Davis | a6a2873 | 2019-11-18 23:00:34 | [diff] [blame] | 796 | |
| 797 | // Test: subview stride operands are folded correctly w.r.t. base strides. |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 798 | // CHECK: memref.subview %[[ALLOC0]][0, 0, 0] [7, 11, 2] [2, 7, 11] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 799 | // CHECK-SAME: memref<128x96x64xf32, strided<[6144, 64, 1]>> |
| 800 | // CHECK-SAME: to memref<7x11x2xf32, strided<[12288, 448, 11]>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 801 | %6 = memref.subview %0[%c0, %c0, %c0] [%c7, %c11, %c2] [%c2, %c7, %c11] |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 802 | : memref<128x96x64xf32, strided<[6144, 64, 1], offset: 0>> to |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 803 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
| 804 | memref.store %v0, %6[%c0, %c0, %c0] : memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Andy Davis | a6a2873 | 2019-11-18 23:00:34 | [diff] [blame] | 805 | |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 806 | // Test: subview shape are folded, but offsets and strides are not even if base memref is static |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 807 | // CHECK: memref.subview %[[ALLOC0]][%[[ARG0]], %[[ARG0]], %[[ARG0]]] [7, 11, 2] [%[[ARG1]], %[[ARG1]], %[[ARG1]]] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 808 | // CHECK-SAME: memref<128x96x64xf32, strided<[6144, 64, 1]>> to |
Alex Zinenko | 2791162b | 2022-09-15 16:29:14 | [diff] [blame] | 809 | // CHECK-SAME: memref<7x11x2xf32, strided<[?, ?, ?], offset: ?>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 810 | %10 = memref.subview %0[%arg0, %arg0, %arg0] [%c7, %c11, %c2] [%arg1, %arg1, %arg1] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 811 | memref<128x96x64xf32, strided<[6144, 64, 1], offset: 0>> to |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 812 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 813 | memref.store %v0, %10[%arg1, %arg1, %arg1] : |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 814 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 815 | |
| 816 | // Test: subview strides are folded, but offsets and shape are not even if base memref is static |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 817 | // CHECK: memref.subview %[[ALLOC0]][%[[ARG0]], %[[ARG0]], %[[ARG0]]] [%[[ARG1]], %[[ARG1]], %[[ARG1]]] [2, 7, 11] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 818 | // CHECK-SAME: memref<128x96x64xf32, strided<[6144, 64, 1]>> to |
| 819 | // CHECK-SAME: memref<?x?x?xf32, strided<[12288, 448, 11], offset: ?>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 820 | %11 = memref.subview %0[%arg0, %arg0, %arg0] [%arg1, %arg1, %arg1] [%c2, %c7, %c11] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 821 | memref<128x96x64xf32, strided<[6144, 64, 1], offset: 0>> to |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 822 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 823 | memref.store %v0, %11[%arg0, %arg0, %arg0] : |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 824 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 825 | |
| 826 | // Test: subview offsets are folded, but strides and shape are not even if base memref is static |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 827 | // CHECK: memref.subview %[[ALLOC0]][1, 2, 7] [%[[ARG1]], %[[ARG1]], %[[ARG1]]] [%[[ARG0]], %[[ARG0]], %[[ARG0]]] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 828 | // CHECK-SAME: memref<128x96x64xf32, strided<[6144, 64, 1]>> to |
| 829 | // CHECK-SAME: memref<?x?x?xf32, strided<[?, ?, ?], offset: 6279>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 830 | %13 = memref.subview %0[%c1, %c2, %c7] [%arg1, %arg1, %arg1] [%arg0, %arg0, %arg0] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 831 | memref<128x96x64xf32, strided<[6144, 64, 1], offset: 0>> to |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 832 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 833 | memref.store %v0, %13[%arg1, %arg1, %arg1] : |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 834 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 835 | |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 836 | // CHECK: %[[ALLOC2:.*]] = memref.alloc(%[[ARG0]], %[[ARG0]], %[[ARG1]]) |
| 837 | %14 = memref.alloc(%arg0, %arg0, %arg1) : memref<?x?x?xf32> |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 838 | // Test: subview shape are folded, even if base memref is not static |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 839 | // CHECK: memref.subview %[[ALLOC2]][%[[ARG0]], %[[ARG0]], %[[ARG0]]] [7, 11, 2] [%[[ARG1]], %[[ARG1]], %[[ARG1]]] : |
Nicolas Vasilache | 63c0e72 | 2020-05-12 21:17:34 | [diff] [blame] | 840 | // CHECK-SAME: memref<?x?x?xf32> to |
Alex Zinenko | 2791162b | 2022-09-15 16:29:14 | [diff] [blame] | 841 | // CHECK-SAME: memref<7x11x2xf32, strided<[?, ?, ?], offset: ?>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 842 | %15 = memref.subview %14[%arg0, %arg0, %arg0] [%c7, %c11, %c2] [%arg1, %arg1, %arg1] : |
Nicolas Vasilache | 63c0e72 | 2020-05-12 21:17:34 | [diff] [blame] | 843 | memref<?x?x?xf32> to |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 844 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
| 845 | memref.store %v0, %15[%arg1, %arg1, %arg1] : memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 846 | |
Nicolas Vasilache | 63c0e72 | 2020-05-12 21:17:34 | [diff] [blame] | 847 | // TEST: subview strides are folded, in the type only the most minor stride is folded. |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 848 | // CHECK: memref.subview %[[ALLOC2]][%[[ARG0]], %[[ARG0]], %[[ARG0]]] [%[[ARG1]], %[[ARG1]], %[[ARG1]]] [2, 2, 2] : |
Nicolas Vasilache | 63c0e72 | 2020-05-12 21:17:34 | [diff] [blame] | 849 | // CHECK-SAME: memref<?x?x?xf32> to |
Alex Zinenko | 2791162b | 2022-09-15 16:29:14 | [diff] [blame] | 850 | // CHECK-SAME: memref<?x?x?xf32, strided<[?, ?, 2], offset: ?>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 851 | %16 = memref.subview %14[%arg0, %arg0, %arg0] [%arg1, %arg1, %arg1] [%c2, %c2, %c2] : |
Nicolas Vasilache | 63c0e72 | 2020-05-12 21:17:34 | [diff] [blame] | 852 | memref<?x?x?xf32> to |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 853 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
| 854 | memref.store %v0, %16[%arg0, %arg0, %arg0] : memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 855 | |
Nicolas Vasilache | 63c0e72 | 2020-05-12 21:17:34 | [diff] [blame] | 856 | // TEST: subview offsets are folded but the type offset remains dynamic, when the base memref is not static |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 857 | // CHECK: memref.subview %[[ALLOC2]][1, 1, 1] [%[[ARG0]], %[[ARG0]], %[[ARG0]]] [%[[ARG1]], %[[ARG1]], %[[ARG1]]] : |
Nicolas Vasilache | 63c0e72 | 2020-05-12 21:17:34 | [diff] [blame] | 858 | // CHECK-SAME: memref<?x?x?xf32> to |
Alex Zinenko | 2791162b | 2022-09-15 16:29:14 | [diff] [blame] | 859 | // CHECK-SAME: memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 860 | %17 = memref.subview %14[%c1, %c1, %c1] [%arg0, %arg0, %arg0] [%arg1, %arg1, %arg1] : |
Nicolas Vasilache | 63c0e72 | 2020-05-12 21:17:34 | [diff] [blame] | 861 | memref<?x?x?xf32> to |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 862 | memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
| 863 | memref.store %v0, %17[%arg0, %arg0, %arg0] : memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 864 | |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 865 | // CHECK: %[[ALLOC3:.*]] = memref.alloc() : memref<128x64xf32> |
| 866 | %18 = memref.alloc() : memref<128x64xf32> |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 867 | %c4 = arith.constant 4 : index |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 868 | |
| 869 | // TEST: subview strides are maintained when sizes are folded |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 870 | // CHECK: memref.subview %[[ALLOC3]][%arg1, %arg1] [2, 4] [1, 1] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 871 | // CHECK-SAME: memref<128x64xf32> to |
| 872 | // CHECK-SAME: memref<2x4xf32, strided<[64, 1], offset: ?> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 873 | %19 = memref.subview %18[%arg1, %arg1] [%c2, %c4] [1, 1] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 874 | memref<128x64xf32> to |
| 875 | memref<?x?xf32, strided<[64, 1], offset: ?>> |
| 876 | memref.store %v0, %19[%arg1, %arg1] : memref<?x?xf32, strided<[64, 1], offset: ?>> |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 877 | |
| 878 | // TEST: subview strides and sizes are maintained when offsets are folded |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 879 | // CHECK: memref.subview %[[ALLOC3]][2, 4] [12, 4] [1, 1] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 880 | // CHECK-SAME: memref<128x64xf32> to |
| 881 | // CHECK-SAME: memref<12x4xf32, strided<[64, 1], offset: 132>> |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 882 | %20 = memref.subview %18[%c2, %c4] [12, 4] [1, 1] : |
Matthias Springer | 5edf127 | 2025-03-31 17:28:55 | [diff] [blame] | 883 | memref<128x64xf32> to |
| 884 | memref<12x4xf32, strided<[64, 1], offset: ?>> |
| 885 | memref.store %v0, %20[%arg1, %arg1] : memref<12x4xf32, strided<[64, 1], offset: ?>> |
Mahesh Ravishankar | 6db8530 | 2019-11-22 19:41:29 | [diff] [blame] | 886 | |
Andy Davis | a6a2873 | 2019-11-18 23:00:34 | [diff] [blame] | 887 | // Test: dim on subview is rewritten to size operand. |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 888 | %7 = memref.dim %4, %c0 : memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
| 889 | %8 = memref.dim %4, %c1 : memref<?x?x?xf32, strided<[?, ?, ?], offset: ?>> |
Stephan Herhut | f0f3b71 | 2019-11-18 12:31:02 | [diff] [blame] | 890 | |
| 891 | // CHECK: return %[[C7]], %[[C11]] |
Andy Davis | a6a2873 | 2019-11-18 23:00:34 | [diff] [blame] | 892 | return %7, %8 : index, index |
Andy Davis | a4669cd | 2019-11-14 20:22:28 | [diff] [blame] | 893 | } |
Stephen Neuendorffer | 12df427 | 2019-12-05 00:15:10 | [diff] [blame] | 894 | |
| 895 | // CHECK-LABEL: func @index_cast |
| 896 | // CHECK-SAME: %[[ARG_0:arg[0-9]+]]: i16 |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 897 | func.func @index_cast(%arg0: i16) -> (i16) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 898 | %11 = arith.index_cast %arg0 : i16 to index |
| 899 | %12 = arith.index_cast %11 : index to i16 |
Stephen Neuendorffer | 12df427 | 2019-12-05 00:15:10 | [diff] [blame] | 900 | // CHECK: return %[[ARG_0]] : i16 |
| 901 | return %12 : i16 |
| 902 | } |
Stephen Neuendorffer | ed56633 | 2019-12-10 19:59:13 | [diff] [blame] | 903 | |
| 904 | // CHECK-LABEL: func @index_cast_fold |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 905 | func.func @index_cast_fold() -> (i16, index) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 906 | %c4 = arith.constant 4 : index |
| 907 | %1 = arith.index_cast %c4 : index to i16 |
| 908 | %c4_i16 = arith.constant 4 : i16 |
| 909 | %2 = arith.index_cast %c4_i16 : i16 to index |
| 910 | // CHECK-DAG: %[[C4:.*]] = arith.constant 4 : index |
| 911 | // CHECK-DAG: %[[C4_I16:.*]] = arith.constant 4 : i16 |
Stephen Neuendorffer | ed56633 | 2019-12-10 19:59:13 | [diff] [blame] | 912 | // CHECK: return %[[C4_I16]], %[[C4]] : i16, index |
| 913 | return %1, %2 : i16, index |
| 914 | } |
Uday Bondhugula | 3f9cdd4 | 2020-03-30 19:45:40 | [diff] [blame] | 915 | |
| 916 | // CHECK-LABEL: func @remove_dead_else |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 917 | func.func @remove_dead_else(%M : memref<100 x i32>) { |
Uday Bondhugula | 3f9cdd4 | 2020-03-30 19:45:40 | [diff] [blame] | 918 | affine.for %i = 0 to 100 { |
| 919 | affine.load %M[%i] : memref<100xi32> |
| 920 | affine.if affine_set<(d0) : (d0 - 2 >= 0)>(%i) { |
| 921 | affine.for %j = 0 to 100 { |
Tres Popp | f66c876 | 2020-04-27 14:40:00 | [diff] [blame] | 922 | %1 = affine.load %M[%j] : memref<100xi32> |
| 923 | "prevent.dce"(%1) : (i32) -> () |
Uday Bondhugula | 3f9cdd4 | 2020-03-30 19:45:40 | [diff] [blame] | 924 | } |
| 925 | } else { |
| 926 | // Nothing |
| 927 | } |
| 928 | affine.load %M[%i] : memref<100xi32> |
| 929 | } |
| 930 | return |
| 931 | } |
| 932 | // CHECK: affine.if |
| 933 | // CHECK-NEXT: affine.for |
| 934 | // CHECK-NEXT: affine.load |
Tres Popp | f66c876 | 2020-04-27 14:40:00 | [diff] [blame] | 935 | // CHECK-NEXT: "prevent.dce" |
Uday Bondhugula | 3f9cdd4 | 2020-03-30 19:45:40 | [diff] [blame] | 936 | // CHECK-NEXT: } |
| 937 | // CHECK-NEXT: } |
Phoenix Meadowlark | 622aac6 | 2020-04-27 19:59:16 | [diff] [blame] | 938 | |
| 939 | // ----- |
| 940 | |
| 941 | // CHECK-LABEL: func @divi_signed_by_one |
| 942 | // CHECK-SAME: %[[ARG:[a-zA-Z0-9]+]] |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 943 | func.func @divi_signed_by_one(%arg0: i32) -> (i32) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 944 | %c1 = arith.constant 1 : i32 |
| 945 | %res = arith.divsi %arg0, %c1 : i32 |
Phoenix Meadowlark | 622aac6 | 2020-04-27 19:59:16 | [diff] [blame] | 946 | // CHECK: return %[[ARG]] |
| 947 | return %res : i32 |
| 948 | } |
| 949 | |
| 950 | // CHECK-LABEL: func @divi_unsigned_by_one |
| 951 | // CHECK-SAME: %[[ARG:[a-zA-Z0-9]+]] |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 952 | func.func @divi_unsigned_by_one(%arg0: i32) -> (i32) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 953 | %c1 = arith.constant 1 : i32 |
| 954 | %res = arith.divui %arg0, %c1 : i32 |
Phoenix Meadowlark | 622aac6 | 2020-04-27 19:59:16 | [diff] [blame] | 955 | // CHECK: return %[[ARG]] |
| 956 | return %res : i32 |
| 957 | } |
| 958 | |
| 959 | // CHECK-LABEL: func @tensor_divi_signed_by_one |
| 960 | // CHECK-SAME: %[[ARG:[a-zA-Z0-9]+]] |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 961 | func.func @tensor_divi_signed_by_one(%arg0: tensor<4x5xi32>) -> tensor<4x5xi32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 962 | %c1 = arith.constant dense<1> : tensor<4x5xi32> |
| 963 | %res = arith.divsi %arg0, %c1 : tensor<4x5xi32> |
Phoenix Meadowlark | 622aac6 | 2020-04-27 19:59:16 | [diff] [blame] | 964 | // CHECK: return %[[ARG]] |
| 965 | return %res : tensor<4x5xi32> |
| 966 | } |
| 967 | |
| 968 | // CHECK-LABEL: func @tensor_divi_unsigned_by_one |
| 969 | // CHECK-SAME: %[[ARG:[a-zA-Z0-9]+]] |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 970 | func.func @tensor_divi_unsigned_by_one(%arg0: tensor<4x5xi32>) -> tensor<4x5xi32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 971 | %c1 = arith.constant dense<1> : tensor<4x5xi32> |
| 972 | %res = arith.divui %arg0, %c1 : tensor<4x5xi32> |
Phoenix Meadowlark | 622aac6 | 2020-04-27 19:59:16 | [diff] [blame] | 973 | // CHECK: return %[[ARG]] |
| 974 | return %res : tensor<4x5xi32> |
| 975 | } |
Sam McCall | 691e826 | 2020-05-12 13:18:50 | [diff] [blame] | 976 | |
| 977 | // ----- |
| 978 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 979 | // CHECK-LABEL: func @arith.floordivsi_by_one |
Alexandre Eichenberger | 0795715 | 2020-11-04 18:51:10 | [diff] [blame] | 980 | // CHECK-SAME: %[[ARG:[a-zA-Z0-9]+]] |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 981 | func.func @arith.floordivsi_by_one(%arg0: i32) -> (i32) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 982 | %c1 = arith.constant 1 : i32 |
| 983 | %res = arith.floordivsi %arg0, %c1 : i32 |
Alexandre Eichenberger | 0795715 | 2020-11-04 18:51:10 | [diff] [blame] | 984 | // CHECK: return %[[ARG]] |
| 985 | return %res : i32 |
| 986 | } |
| 987 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 988 | // CHECK-LABEL: func @tensor_arith.floordivsi_by_one |
Alexandre Eichenberger | 0795715 | 2020-11-04 18:51:10 | [diff] [blame] | 989 | // CHECK-SAME: %[[ARG:[a-zA-Z0-9]+]] |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 990 | func.func @tensor_arith.floordivsi_by_one(%arg0: tensor<4x5xi32>) -> tensor<4x5xi32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 991 | %c1 = arith.constant dense<1> : tensor<4x5xi32> |
| 992 | %res = arith.floordivsi %arg0, %c1 : tensor<4x5xi32> |
Alexandre Eichenberger | 0795715 | 2020-11-04 18:51:10 | [diff] [blame] | 993 | // CHECK: return %[[ARG]] |
| 994 | return %res : tensor<4x5xi32> |
| 995 | } |
| 996 | |
long.chen | 631e54a | 2024-03-22 15:52:47 | [diff] [blame] | 997 | // CHECK-LABEL: func @arith.floordivsi_by_one_overflow |
| 998 | func.func @arith.floordivsi_by_one_overflow() -> i64 { |
| 999 | %neg_one = arith.constant -1 : i64 |
| 1000 | %min_int = arith.constant -9223372036854775808 : i64 |
| 1001 | // CHECK: arith.floordivsi |
| 1002 | %poision = arith.floordivsi %min_int, %neg_one : i64 |
| 1003 | return %poision : i64 |
| 1004 | } |
| 1005 | |
Alexandre Eichenberger | 0795715 | 2020-11-04 18:51:10 | [diff] [blame] | 1006 | // ----- |
| 1007 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 1008 | // CHECK-LABEL: func @arith.ceildivsi_by_one |
Alexandre Eichenberger | 0795715 | 2020-11-04 18:51:10 | [diff] [blame] | 1009 | // CHECK-SAME: %[[ARG:[a-zA-Z0-9]+]] |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 1010 | func.func @arith.ceildivsi_by_one(%arg0: i32) -> (i32) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 1011 | %c1 = arith.constant 1 : i32 |
| 1012 | %res = arith.ceildivsi %arg0, %c1 : i32 |
Alexandre Eichenberger | 0795715 | 2020-11-04 18:51:10 | [diff] [blame] | 1013 | // CHECK: return %[[ARG]] |
| 1014 | return %res : i32 |
| 1015 | } |
| 1016 | |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 1017 | // CHECK-LABEL: func @tensor_arith.ceildivsi_by_one |
Alexandre Eichenberger | 0795715 | 2020-11-04 18:51:10 | [diff] [blame] | 1018 | // CHECK-SAME: %[[ARG:[a-zA-Z0-9]+]] |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 1019 | func.func @tensor_arith.ceildivsi_by_one(%arg0: tensor<4x5xi32>) -> tensor<4x5xi32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 1020 | %c1 = arith.constant dense<1> : tensor<4x5xi32> |
| 1021 | %res = arith.ceildivsi %arg0, %c1 : tensor<4x5xi32> |
Alexandre Eichenberger | 0795715 | 2020-11-04 18:51:10 | [diff] [blame] | 1022 | // CHECK: return %[[ARG]] |
| 1023 | return %res : tensor<4x5xi32> |
| 1024 | } |
| 1025 | |
| 1026 | // ----- |
| 1027 | |
lipracer | 8165eaa | 2021-11-11 01:47:47 | [diff] [blame] | 1028 | // CHECK-LABEL: func @arith.ceildivui_by_one |
| 1029 | // CHECK-SAME: %[[ARG:[a-zA-Z0-9]+]] |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 1030 | func.func @arith.ceildivui_by_one(%arg0: i32) -> (i32) { |
lipracer | 8165eaa | 2021-11-11 01:47:47 | [diff] [blame] | 1031 | %c1 = arith.constant 1 : i32 |
| 1032 | %res = arith.ceildivui %arg0, %c1 : i32 |
| 1033 | // CHECK: return %[[ARG]] |
| 1034 | return %res : i32 |
| 1035 | } |
| 1036 | |
| 1037 | // CHECK-LABEL: func @tensor_arith.ceildivui_by_one |
| 1038 | // CHECK-SAME: %[[ARG:[a-zA-Z0-9]+]] |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 1039 | func.func @tensor_arith.ceildivui_by_one(%arg0: tensor<4x5xi32>) -> tensor<4x5xi32> { |
lipracer | 8165eaa | 2021-11-11 01:47:47 | [diff] [blame] | 1040 | %c1 = arith.constant dense<1> : tensor<4x5xi32> |
| 1041 | %res = arith.ceildivui %arg0, %c1 : tensor<4x5xi32> |
| 1042 | // CHECK: return %[[ARG]] |
| 1043 | return %res : tensor<4x5xi32> |
| 1044 | } |
| 1045 | |
| 1046 | // ----- |
| 1047 | |
Sam McCall | 691e826 | 2020-05-12 13:18:50 | [diff] [blame] | 1048 | // CHECK-LABEL: func @memref_cast_folding_subview |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 1049 | func.func @memref_cast_folding_subview(%arg0: memref<4x5xf32>, %i: index) -> (memref<?x?xf32, strided<[?, ?], offset: ?>>) { |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 1050 | %0 = memref.cast %arg0 : memref<4x5xf32> to memref<?x?xf32> |
| 1051 | // CHECK-NEXT: memref.subview %{{.*}}: memref<4x5xf32> |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 1052 | %1 = memref.subview %0[%i, %i][%i, %i][%i, %i]: memref<?x?xf32> to memref<?x?xf32, strided<[?, ?], offset: ?>> |
Alex Zinenko | 519847f | 2022-08-30 08:23:57 | [diff] [blame] | 1053 | return %1: memref<?x?xf32, strided<[?, ?], offset: ?>> |
Sam McCall | 691e826 | 2020-05-12 13:18:50 | [diff] [blame] | 1054 | } |
| 1055 | |
Nicolas Vasilache | e0b99a5 | 2020-05-13 02:21:36 | [diff] [blame] | 1056 | // ----- |
| 1057 | |
Nicolas Vasilache | e0b99a5 | 2020-05-13 02:21:36 | [diff] [blame] | 1058 | // CHECK-LABEL: func @memref_cast_folding_subview_static( |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 1059 | func.func @memref_cast_folding_subview_static(%V: memref<16x16xf32>, %a: index, %b: index) |
Matthias Springer | 6dc8de7 | 2024-06-23 17:05:00 | [diff] [blame] | 1060 | -> memref<3x4xf32, strided<[?, 1]>> |
Nicolas Vasilache | e0b99a5 | 2020-05-13 02:21:36 | [diff] [blame] | 1061 | { |
Julian Gross | e231070 | 2021-02-10 12:53:11 | [diff] [blame] | 1062 | %0 = memref.cast %V : memref<16x16xf32> to memref<?x?xf32> |
Matthias Springer | 6dc8de7 | 2024-06-23 17:05:00 | [diff] [blame] | 1063 | %1 = memref.subview %0[0, 0][3, 4][1, 1] : memref<?x?xf32> to memref<3x4xf32, strided<[?, 1]>> |
Nicolas Vasilache | e0b99a5 | 2020-05-13 02:21:36 | [diff] [blame] | 1064 | |
Alex Zinenko | 2791162b | 2022-09-15 16:29:14 | [diff] [blame] | 1065 | // CHECK: memref.subview{{.*}}: memref<16x16xf32> to memref<3x4xf32, strided<[16, 1]>> |
Matthias Springer | 6dc8de7 | 2024-06-23 17:05:00 | [diff] [blame] | 1066 | return %1: memref<3x4xf32, strided<[?, 1]>> |
Nicolas Vasilache | e0b99a5 | 2020-05-13 02:21:36 | [diff] [blame] | 1067 | } |
Alexander Belyaev | c3098e4 | 2020-05-28 11:36:40 | [diff] [blame] | 1068 | |
| 1069 | // ----- |
| 1070 | |
Matthias Springer | 060208b | 2021-06-22 07:49:08 | [diff] [blame] | 1071 | // CHECK-LABEL: func @slice |
Nicolas Vasilache | 787bf5e | 2020-10-02 09:40:52 | [diff] [blame] | 1072 | // CHECK-SAME: %[[ARG0:[0-9a-z]*]]: index, %[[ARG1:[0-9a-z]*]]: index |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 1073 | func.func @slice(%t: tensor<8x16x4xf32>, %arg0 : index, %arg1 : index) |
Nicolas Vasilache | b3c227a | 2021-02-18 22:03:02 | [diff] [blame] | 1074 | -> tensor<?x?x?xf32> |
Nicolas Vasilache | 787bf5e | 2020-10-02 09:40:52 | [diff] [blame] | 1075 | { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 1076 | %c0 = arith.constant 0 : index |
| 1077 | %c1 = arith.constant 1 : index |
| 1078 | %c2 = arith.constant 2 : index |
| 1079 | %c7 = arith.constant 7 : index |
| 1080 | %c11 = arith.constant 11 : index |
Nicolas Vasilache | 787bf5e | 2020-10-02 09:40:52 | [diff] [blame] | 1081 | |
Matthias Springer | 060208b | 2021-06-22 07:49:08 | [diff] [blame] | 1082 | // CHECK: tensor.extract_slice %{{.*}}[0, 0, 0] [7, 11, 2] [1, 1, 1] : |
Nicolas Vasilache | 787bf5e | 2020-10-02 09:40:52 | [diff] [blame] | 1083 | // CHECK-SAME: tensor<8x16x4xf32> to tensor<7x11x2xf32> |
Nicolas Vasilache | b3c227a | 2021-02-18 22:03:02 | [diff] [blame] | 1084 | // tensor.cast gets folded away in consumer. |
| 1085 | // CHECK-NOT: tensor.cast |
Matthias Springer | 060208b | 2021-06-22 07:49:08 | [diff] [blame] | 1086 | %1 = tensor.extract_slice %t[%c0, %c0, %c0] [%c7, %c11, %c2] [%c1, %c1, %c1] |
Nicolas Vasilache | 787bf5e | 2020-10-02 09:40:52 | [diff] [blame] | 1087 | : tensor<8x16x4xf32> to tensor<?x?x?xf32> |
| 1088 | |
Matthias Springer | 060208b | 2021-06-22 07:49:08 | [diff] [blame] | 1089 | // Test: slice with one dynamic operand can also be folded. |
| 1090 | // CHECK: tensor.extract_slice %{{.*}}[0, 0, 0] [2, %[[ARG0]], 2] [1, 1, 1] : |
Nicolas Vasilache | b3c227a | 2021-02-18 22:03:02 | [diff] [blame] | 1091 | // CHECK-SAME: tensor<7x11x2xf32> to tensor<2x?x2xf32> |
Sean Silva | 129d6e5 | 2020-12-16 00:47:19 | [diff] [blame] | 1092 | // CHECK: tensor.cast %{{.*}} : tensor<2x?x2xf32> to tensor<?x?x?xf32> |
Matthias Springer | 060208b | 2021-06-22 07:49:08 | [diff] [blame] | 1093 | %2 = tensor.extract_slice %1[%c0, %c0, %c0] [%c2, %arg0, %c2] [%c1, %c1, %c1] |
Nicolas Vasilache | 787bf5e | 2020-10-02 09:40:52 | [diff] [blame] | 1094 | : tensor<?x?x?xf32> to tensor<?x?x?xf32> |
| 1095 | |
| 1096 | return %2 : tensor<?x?x?xf32> |
| 1097 | } |
Nicolas Vasilache | b3c227a | 2021-02-18 22:03:02 | [diff] [blame] | 1098 | |
KareemErgawy-TomTom | e5f2898 | 2021-03-27 18:40:10 | [diff] [blame] | 1099 | // ----- |
| 1100 | |
| 1101 | // CHECK-LABEL: func @fold_trunci |
| 1102 | // CHECK-SAME: (%[[ARG0:[0-9a-z]*]]: i1) |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 1103 | func.func @fold_trunci(%arg0: i1) -> i1 attributes {} { |
KareemErgawy-TomTom | e5f2898 | 2021-03-27 18:40:10 | [diff] [blame] | 1104 | // CHECK-NEXT: return %[[ARG0]] : i1 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 1105 | %0 = arith.extui %arg0 : i1 to i8 |
| 1106 | %1 = arith.trunci %0 : i8 to i1 |
KareemErgawy-TomTom | e5f2898 | 2021-03-27 18:40:10 | [diff] [blame] | 1107 | return %1 : i1 |
| 1108 | } |
| 1109 | |
| 1110 | // ----- |
| 1111 | |
| 1112 | // CHECK-LABEL: func @fold_trunci_vector |
| 1113 | // CHECK-SAME: (%[[ARG0:[0-9a-z]*]]: vector<4xi1>) |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 1114 | func.func @fold_trunci_vector(%arg0: vector<4xi1>) -> vector<4xi1> attributes {} { |
KareemErgawy-TomTom | e5f2898 | 2021-03-27 18:40:10 | [diff] [blame] | 1115 | // CHECK-NEXT: return %[[ARG0]] : vector<4xi1> |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 1116 | %0 = arith.extui %arg0 : vector<4xi1> to vector<4xi8> |
| 1117 | %1 = arith.trunci %0 : vector<4xi8> to vector<4xi1> |
KareemErgawy-TomTom | e5f2898 | 2021-03-27 18:40:10 | [diff] [blame] | 1118 | return %1 : vector<4xi1> |
| 1119 | } |
| 1120 | |
| 1121 | // ----- |
| 1122 | |
Jakub Kuderski | ab85aec | 2023-04-27 15:13:46 | [diff] [blame] | 1123 | // CHECK-LABEL: func @fold_trunci |
KareemErgawy-TomTom | e5f2898 | 2021-03-27 18:40:10 | [diff] [blame] | 1124 | // CHECK-SAME: (%[[ARG0:[0-9a-z]*]]: i1) |
Jakub Kuderski | ab85aec | 2023-04-27 15:13:46 | [diff] [blame] | 1125 | func.func @fold_trunci(%arg0: i1) -> i2 attributes {} { |
| 1126 | // CHECK-NEXT: %[[RES:[0-9a-z]*]] = arith.extui %[[ARG0]] : i1 to i2 |
KareemErgawy-TomTom | e5f2898 | 2021-03-27 18:40:10 | [diff] [blame] | 1127 | // CHECK-NEXT: return %[[RES]] : i2 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 1128 | %0 = arith.extui %arg0 : i1 to i8 |
| 1129 | %1 = arith.trunci %0 : i8 to i2 |
KareemErgawy-TomTom | e5f2898 | 2021-03-27 18:40:10 | [diff] [blame] | 1130 | return %1 : i2 |
| 1131 | } |
| 1132 | |
| 1133 | // ----- |
| 1134 | |
Jakub Kuderski | ab85aec | 2023-04-27 15:13:46 | [diff] [blame] | 1135 | // CHECK-LABEL: func @fold_trunci_vector |
KareemErgawy-TomTom | e5f2898 | 2021-03-27 18:40:10 | [diff] [blame] | 1136 | // CHECK-SAME: (%[[ARG0:[0-9a-z]*]]: vector<4xi1>) |
Jakub Kuderski | ab85aec | 2023-04-27 15:13:46 | [diff] [blame] | 1137 | func.func @fold_trunci_vector(%arg0: vector<4xi1>) -> vector<4xi2> attributes {} { |
| 1138 | // CHECK-NEXT: %[[RES:[0-9a-z]*]] = arith.extui %[[ARG0]] : vector<4xi1> to vector<4xi2> |
KareemErgawy-TomTom | e5f2898 | 2021-03-27 18:40:10 | [diff] [blame] | 1139 | // CHECK-NEXT: return %[[RES]] : vector<4xi2> |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 1140 | %0 = arith.extui %arg0 : vector<4xi1> to vector<4xi8> |
| 1141 | %1 = arith.trunci %0 : vector<4xi8> to vector<4xi2> |
KareemErgawy-TomTom | e5f2898 | 2021-03-27 18:40:10 | [diff] [blame] | 1142 | return %1 : vector<4xi2> |
| 1143 | } |
KareemErgawy-TomTom | c52a5f2 | 2021-03-29 06:33:56 | [diff] [blame] | 1144 | |
| 1145 | // ----- |
| 1146 | |
| 1147 | // CHECK-LABEL: func @fold_trunci_sexti |
| 1148 | // CHECK-SAME: (%[[ARG0:[0-9a-z]*]]: i1) |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 1149 | func.func @fold_trunci_sexti(%arg0: i1) -> i1 attributes {} { |
KareemErgawy-TomTom | c52a5f2 | 2021-03-29 06:33:56 | [diff] [blame] | 1150 | // CHECK-NEXT: return %[[ARG0]] : i1 |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 1151 | %0 = arith.extsi %arg0 : i1 to i8 |
| 1152 | %1 = arith.trunci %0 : i8 to i1 |
KareemErgawy-TomTom | c52a5f2 | 2021-03-29 06:33:56 | [diff] [blame] | 1153 | return %1 : i1 |
| 1154 | } |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1155 | |
| 1156 | // CHECK-LABEL: func @simple_clone_elimination |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 1157 | func.func @simple_clone_elimination() -> memref<5xf32> { |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1158 | %ret = memref.alloc() : memref<5xf32> |
Alexander Belyaev | 57470ab | 2021-11-25 10:42:16 | [diff] [blame] | 1159 | %temp = bufferization.clone %ret : memref<5xf32> to memref<5xf32> |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1160 | memref.dealloc %temp : memref<5xf32> |
| 1161 | return %ret : memref<5xf32> |
| 1162 | } |
| 1163 | // CHECK-NEXT: %[[ret:.*]] = memref.alloc() |
Alexander Belyaev | 57470ab | 2021-11-25 10:42:16 | [diff] [blame] | 1164 | // CHECK-NOT: %{{.*}} = bufferization.clone |
Thomas Preud'homme | 17f4f23 | 2021-03-28 00:03:37 | [diff] [blame] | 1165 | // CHECK-NOT: memref.dealloc %{{.*}} |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1166 | // CHECK: return %[[ret]] |
| 1167 | |
| 1168 | // ----- |
| 1169 | |
| 1170 | // CHECK-LABEL: func @clone_loop_alloc |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 1171 | func.func @clone_loop_alloc(%arg0: index, %arg1: index, %arg2: index, %arg3: memref<2xf32>, %arg4: memref<2xf32>) { |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1172 | %0 = memref.alloc() : memref<2xf32> |
| 1173 | memref.dealloc %0 : memref<2xf32> |
Alexander Belyaev | 57470ab | 2021-11-25 10:42:16 | [diff] [blame] | 1174 | %1 = bufferization.clone %arg3 : memref<2xf32> to memref<2xf32> |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1175 | %2 = scf.for %arg5 = %arg0 to %arg1 step %arg2 iter_args(%arg6 = %1) -> (memref<2xf32>) { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 1176 | %3 = arith.cmpi eq, %arg5, %arg1 : index |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1177 | memref.dealloc %arg6 : memref<2xf32> |
| 1178 | %4 = memref.alloc() : memref<2xf32> |
Alexander Belyaev | 57470ab | 2021-11-25 10:42:16 | [diff] [blame] | 1179 | %5 = bufferization.clone %4 : memref<2xf32> to memref<2xf32> |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1180 | memref.dealloc %4 : memref<2xf32> |
Alexander Belyaev | 57470ab | 2021-11-25 10:42:16 | [diff] [blame] | 1181 | %6 = bufferization.clone %5 : memref<2xf32> to memref<2xf32> |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1182 | memref.dealloc %5 : memref<2xf32> |
| 1183 | scf.yield %6 : memref<2xf32> |
| 1184 | } |
Alexander Belyaev | ebc8153 | 2022-02-01 17:07:33 | [diff] [blame] | 1185 | memref.copy %2, %arg4 : memref<2xf32> to memref<2xf32> |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1186 | memref.dealloc %2 : memref<2xf32> |
| 1187 | return |
| 1188 | } |
| 1189 | |
Alexander Belyaev | 57470ab | 2021-11-25 10:42:16 | [diff] [blame] | 1190 | // CHECK-NEXT: %[[ALLOC0:.*]] = bufferization.clone |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1191 | // CHECK-NEXT: %[[ALLOC1:.*]] = scf.for |
| 1192 | // CHECK-NEXT: memref.dealloc |
| 1193 | // CHECK-NEXT: %[[ALLOC2:.*]] = memref.alloc |
| 1194 | // CHECK-NEXT: scf.yield %[[ALLOC2]] |
Alexander Belyaev | ebc8153 | 2022-02-01 17:07:33 | [diff] [blame] | 1195 | // CHECK: memref.copy %[[ALLOC1]] |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1196 | // CHECK-NEXT: memref.dealloc %[[ALLOC1]] |
| 1197 | |
| 1198 | // ----- |
| 1199 | |
| 1200 | // CHECK-LABEL: func @clone_nested_region |
River Riddle | cda6aa7 | 2022-04-20 23:22:21 | [diff] [blame] | 1201 | func.func @clone_nested_region(%arg0: index, %arg1: index, %arg2: index) -> memref<?x?xf32> { |
Mogball | a54f4ea | 2021-10-12 23:14:57 | [diff] [blame] | 1202 | %cmp = arith.cmpi eq, %arg0, %arg1 : index |
| 1203 | %0 = arith.cmpi eq, %arg0, %arg1 : index |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1204 | %1 = memref.alloc(%arg0, %arg0) : memref<?x?xf32> |
| 1205 | %2 = scf.if %0 -> (memref<?x?xf32>) { |
William S. Moses | ca27260 | 2021-04-22 02:26:10 | [diff] [blame] | 1206 | %3 = scf.if %cmp -> (memref<?x?xf32>) { |
Alexander Belyaev | 57470ab | 2021-11-25 10:42:16 | [diff] [blame] | 1207 | %9 = bufferization.clone %1 : memref<?x?xf32> to memref<?x?xf32> |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1208 | scf.yield %9 : memref<?x?xf32> |
| 1209 | } else { |
| 1210 | %7 = memref.alloc(%arg0, %arg1) : memref<?x?xf32> |
Alexander Belyaev | 57470ab | 2021-11-25 10:42:16 | [diff] [blame] | 1211 | %10 = bufferization.clone %7 : memref<?x?xf32> to memref<?x?xf32> |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1212 | memref.dealloc %7 : memref<?x?xf32> |
| 1213 | scf.yield %10 : memref<?x?xf32> |
| 1214 | } |
Alexander Belyaev | 57470ab | 2021-11-25 10:42:16 | [diff] [blame] | 1215 | %6 = bufferization.clone %3 : memref<?x?xf32> to memref<?x?xf32> |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1216 | memref.dealloc %3 : memref<?x?xf32> |
| 1217 | scf.yield %6 : memref<?x?xf32> |
| 1218 | } else { |
| 1219 | %3 = memref.alloc(%arg1, %arg1) : memref<?x?xf32> |
Alexander Belyaev | 57470ab | 2021-11-25 10:42:16 | [diff] [blame] | 1220 | %6 = bufferization.clone %3 : memref<?x?xf32> to memref<?x?xf32> |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1221 | memref.dealloc %3 : memref<?x?xf32> |
| 1222 | scf.yield %6 : memref<?x?xf32> |
| 1223 | } |
| 1224 | memref.dealloc %1 : memref<?x?xf32> |
| 1225 | return %2 : memref<?x?xf32> |
| 1226 | } |
| 1227 | |
| 1228 | // CHECK: %[[ALLOC1:.*]] = memref.alloc |
| 1229 | // CHECK-NEXT: %[[ALLOC2:.*]] = scf.if |
| 1230 | // CHECK-NEXT: %[[ALLOC3_1:.*]] = scf.if |
Alexander Belyaev | 57470ab | 2021-11-25 10:42:16 | [diff] [blame] | 1231 | // CHECK-NEXT: %[[ALLOC4_1:.*]] = bufferization.clone %[[ALLOC1]] |
Alexander Belyaev | 465b9a4 | 2021-03-31 07:34:03 | [diff] [blame] | 1232 | // CHECK-NEXT: scf.yield %[[ALLOC4_1]] |
| 1233 | // CHECK: %[[ALLOC4_2:.*]] = memref.alloc |
| 1234 | // CHECK-NEXT: scf.yield %[[ALLOC4_2]] |
| 1235 | // CHECK: scf.yield %[[ALLOC3_1]] |
| 1236 | // CHECK: %[[ALLOC3_2:.*]] = memref.alloc |
| 1237 | // CHECK-NEXT: scf.yield %[[ALLOC3_2]] |
| 1238 | // CHECK: memref.dealloc %[[ALLOC1]] |
| 1239 | // CHECK-NEXT: return %[[ALLOC2]] |
Billy Zhu | eb42868 | 2024-01-08 18:29:32 | [diff] [blame] | 1240 | |
| 1241 | // ----- |
| 1242 | |
| 1243 | // CHECK-LABEL: func @test_materialize_failure |
| 1244 | func.func @test_materialize_failure() -> i64 { |
| 1245 | %const = index.constant 1234 |
| 1246 | // Cannot materialize this castu's output constant. |
| 1247 | // CHECK: index.castu |
| 1248 | %u = index.castu %const : index to i64 |
| 1249 | return %u: i64 |
| 1250 | } |