<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57596>57596</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [ARM SVE] *_ZI instructions would not be selected in loop bodies: SVEAllActive cannot see through BB boundaries.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          zinechant
      </td>
    </tr>
</table>

<pre>
    I find that all *_ZI (ADD_ZI, MUL_ZI) variants of the instructions would not be selected inside a loop. e.g.
```c++
#include <arm_sve.h>
#include <cstdint>
#include <random>

std::mt19937 mt(0);
const int VB = svcntb();

void test(int n, int8_t* pdata) {
  for (int i = 0; i < n; i++, pdata += VB) {
    svint64_t v = svdup_n_s64(mt());
    v = svmul_n_s64_m(svptrue_b64(), v, 3);
    v = svadd_n_s64_m(svptrue_b64(), v, 1);
    svst1(svptrue_b64(), (int64_t*)pdata, v);
  }
}
```

Judging from debug log of llc, it seems that:

* The all true predicates get moved out of the loop body during the LICM pass.
* The instructions inside the loop body takes a CopyFromReg predicate as arguments.
* [SVEAllActive](https://github.com/llvm/llvm-project/blob/cff5bef948c91e4919de8a5fb9765e0edc13f3de/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp#L16561) which guards the selection of *_ZI instructions, would not know that the moved-out predicate is all true. (different basic block)

I am not sure if this is a desired feature. Obviously, it would increase instruction counts by not selecting *_ZI variants.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVNtupDgQ_Rr6pTSIS0M3Dzz0ZVrqVaKVZmbzMC8tYxvwxmDkC1H267cMdEJGE2lXQmDsquOqU6eqUuy1vEItega2JRaIlBAkh9vPK372h_MZV0Fygse_HqZVASPRgvTWgKrRhYPojdWOWqF6Ay_KSQa9slBxMFxyajnzJoJxICCVGkLgYRMG0TmIDkEezQ8NkqN_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