<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61784>61784</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
mlir/Affine: affine loop fusion is unable to fuse loops with non-constant extents
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rohany
</td>
</tr>
</table>
<pre>
The loop fusion pass is unable to fuse loop nests with non-constant extents, like the one shown here:
```
func.func @testing(%arg0: memref<?xf32>) {
%cst = arith.constant 1.000000e+00 : f32
%cst_0 = arith.constant 2.000000e+00 : f32
%cst_1 = arith.constant 3.000000e+00 : f32
%c0 = arith.constant 0 : index
%dim = memref.dim %arg0, %c0 : memref<?xf32>
affine.for %arg1 = 0 to %dim {
%0 = affine.load %arg0[%arg1] : memref<?xf32>
%1 = arith.addf %0, %cst : f32
affine.store %1, %arg0[%arg1] : memref<?xf32>
}
affine.for %arg1 = 0 to %dim {
%0 = affine.load %arg0[%arg1] : memref<?xf32>
%1 = arith.addf %0, %cst_0 : f32
affine.store %1, %arg0[%arg1] : memref<?xf32>
}
affine.for %arg1 = 0 to %dim {
%0 = affine.load %arg0[%arg1] : memref<?xf32>
%1 = arith.addf %0, %cst_1 : f32
affine.store %1, %arg0[%arg1] : memref<?xf32>
}
return
}
```
Refer to the discussion here https://discourse.llvm.org/t/understanding-the-affine-loop-fusion-pass/69452/8 for comments on scope and potential places in the code to start looking as to where the loop fusion analysis fails.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVU2PozgQ_TXmUgIZ85Fw4JB0lh-w2nvLwQV429iRbba7__3KhmS7o2inNdKMZqKIyHHVq1ev8DN3To4asSXVkVSnhC9-Mra1ZuL6PTkb8d7-NSEoYy4wLE4aDRfuHEgHi-ZnheBN2NhCNDrv4FX6CbTRaW-081x7wDeP2jvCnkDJFwQ_IRiN4CbzqmFCi6Q4EHoi9EBqun3jEmBYdJ-FB5CSenRe6pGwPWEVtyMlxQFmnC0OpHgiRfc2FIwUfxDWANkdrxgAhFW980CKE3Ar_ZTduOUZjR8k7EgpBMCAcZf5TB_lsq_l5o9yiy_kPiy6xkot8O1TtJBzDF_lyOJyE4k93eAey3XD4cMgNWaDsVvyyp2GOV9rfNQ1Vt5orqnKcHErXB03FFKdvl08gn0UiwsxxALXDuII74S6kXbeWIwQW_h3UCC707b45ZV4fvDS_CAtfocXI56ynyaHRb9YfV3ftu7ca33-iQPaoFOwPSFdv7jopMH3YPL-4oL7sY6wLuyaxTrMlPpnzowdCes8Yd2iBdpw_oXUY-onTNfO0uC76WrNabBmwrq6KStGWLeHMK3ezHMwXzAaXG8uCFwLuJjgyJIruCjeowOpI73eiOjpznPrg6m_SD0Cd-G_10jY390HXHP17qSDgUvlskS0hWiKhifY5vWe0jqv6jyZ2no3nPdNyUTZsyYv9w2vWY-7BkVFK1H2iWwZZQUtWEOLsqZ5hljTvslFSfl-lwskJcWZS3XTJpHOLdjW-W5fJoqfUbnrRWbbEJSel9GRkirpvPsvzUuvsJ2VtIR1h6hjmP6q6KfmHt9z_3PFJYtV7eeZjtJPyznrzUxYFzhsP-nFmr-xD9ONfcTRhVb-DQAA__813S38">