<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/114300>114300</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR][Memref] Code block emptied After `--canonicalize` Pass
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tavakkoliamirmohammad
</td>
</tr>
</table>
<pre>
Hi, I’m facing an issue with the following code. After applying the `—canonicalize` option, the main function body becomes empty, eliminating all its operations.
You can view the code and reproduction steps in Compiler Explorer: https://godbolt.org/z/s5oKx48Kq
```
module {
func.func @main() {
%c8_i32 = arith.constant 8 : i32
%c1_i32 = arith.constant 1 : i32
%0 = arith.muli %c1_i32, %c8_i32 : i32
%alloc = memref.alloc() : memref<64xf32>
%alloc_0 = memref.alloc() : memref<64xf32>
affine.for %arg0 = 0 to 64 {
%1 = arith.index_cast %arg0 : index to i32
%2 = arith.divui %1, %c1_i32 : i32
%3 = arith.divui %2, %0 : i32
%4 = arith.remui %2, %0 : i32
%5 = arith.divui %4, %c1_i32 : i32
%c0_i32 = arith.constant 0 : i32
%6 = arith.muli %c1_i32, %3 : i32
%7 = arith.muli %c1_i32, %5 : i32
%8 = arith.addi %c0_i32, %6 : i32
%9 = arith.addi %c0_i32, %7 : i32
%10 = arith.muli %8, %0 : i32
%11 = arith.addi %c0_i32, %10 : i32
%12 = arith.muli %9, %c1_i32 : i32
%13 = arith.addi %11, %12 : i32
%14 = arith.muli %13, %c1_i32 : i32
%15 = arith.addi %c0_i32, %14 : i32
%16 = arith.index_cast %15 : i32 to index
%17 = memref.load %alloc_0[%16] : memref<64xf32>
%18 = arith.muli %9, %0 : i32
%19 = arith.addi %c0_i32, %18 : i32
%20 = arith.muli %8, %c1_i32 : i32
%21 = arith.addi %19, %20 : i32
%22 = arith.muli %21, %c1_i32 : i32
%23 = arith.addi %c0_i32, %22 : i32
%24 = arith.index_cast %23 : i32 to index
memref.store %17, %alloc[%24] : memref<64xf32>
}
memref.dealloc %alloc : memref<64xf32>
memref.dealloc %alloc_0 : memref<64xf32>
return
}
}
```
Calling the `--canonicalize`
```
module {
func.func @main() {
return
}
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyslk-PozYUwD-Nc3ka5D8QyIFDNpmoq22lqreeRgZM4o7B1DaZmf30lU2yIbOQpFWlUQab93v_sR-3Vu5bIXKUfEHJdsF7d9Amd_zIX1-1kryRptEH3jS8WhS6-sh_kYhu4Ct6pijDaLVqoOalbPfAW5DW9gLepDuAOwiotVL6zb8rdSUiWNdOGOBdpz78phdBS3zWFJe81a0suZLfBVpi0J2TuvXWvGTDZQt135Z-E7wrUIhSN8KCaDr34eWEko1suQvuKAXSWdCdMNwzNkJ4i_B6-P1T91DyFo5SvAX93kXgbQVGdEZX_WDHOtFZkC1sdNNJJQw8v3dKG2EQW8PBuc4itkZ0h-hur6tCKxdps0d09x3RnU30t_c4-_b32LIPefgLy0ZXvRKA0i_DGkKQkf8BFGMfNqIZoquxCACiSZm9SEYBsS1wI90hKnVrHW8dZOC9k4xey5M5eTIpj0eiTa_kRYfP9diBn1mulC4D34jGiDoKG-dA2Pq0jdhmGb_XjCL2_DP_gv-rBl7XshVRrU1QZvaDJgxOwzK-zmSwR0axyrYS7y8lt24EryFsewVXsQZ6nNRKHvuQKnLOEpnOUiDZFHnOL56B4hFkRPMYlExZih_xscRzfTNna3mvc9gMmN4DkxkwG4G8quTF7xO4nAFX98B0BiRTn0d2pwiE3DNHZlE6YW_1SP0ImzBKzu1JZrF4wiBhD1lM7oYZz6HL2S-R_Ch--Ar9u89wOj4wlObV6CzxN5zXj5Lt3fNj0JbdyPhsme42FJk4nYdT5FZH3cw3nWorcnaVzvlKp1qKPnRu0ameugqTzqLxbIUpu1nhU12t00YM5T7ZGq6GUF8aP1JflG4vi5PaSpwurcvtdVvJDPeC75JGuN605_UPZy4P1yPChis1Gp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