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

    <tr>
        <th>Summary</th>
        <td>
            aarch64 llvm 14 regression with vectors: Assertion `mutationIsSane(Rule, Query, Mutation) && "legality mutation invalid for match"' failed
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            bug,
            backend:AArch64,
            regression
      </td>
    </tr>

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

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

<pre>
    Does *not* affect LLVM 13.0.1.
Tested with LLVM 14.0.6. Have not yet confirmed whether it affects trunk.

Reduced LLVM IR:

```llvm
define internal fastcc i16 @testOneCtzVector.2() {
Entry:
  %0 = call <64 x i16> @llvm.cttz.v64i16(<64 x i16> zeroinitializer, i1 false)
  %1 = trunc <64 x i16> %0 to <64 x i5>
  store <64 x i5> %1, <64 x i5>* null, align 64
  ret i16 0
}

; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
declare <64 x i16> @llvm.cttz.v64i16(<64 x i16>, i1 immarg) #0

attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
```

Reproduction:

```
$ ~/local/llvm14-debug/bin/clang -c reduced.ll  -target aarch64-linux-unknown
warning: overriding the module target triple with aarch64-unknown-linux-unknown [-Woverride-module]
clang: /home/andy/Downloads/llvm-project-14/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp:198: llvm::LegalizeActionStep llvm::LegalizeRuleSet::apply(const llvm::LegalityQuery&) const: Assertion `mutationIsSane(Rule, Query, Mutation) && "legality mutation invalid for match"' failed.
```

Downstream issue: TBD

Apologies for not catching this during the RC phase.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVE1v4zYQ_TXyhbAgS7IsH3xw7M02QBZFk8X2TEkjmQ1FCiTlrPPr-0jLaxvbFkUvBQxZ4sebN2_eTKWb02av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