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

    <tr>
        <th>Summary</th>
        <td>
            Splat of not could be canonicalised
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:instcombine
      </td>
    </tr>

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

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

<pre>
    Alive link: https://alive2.llvm.org/ce/z/4KIIpC

If we have a scalar value that we want negate and then splat, we can either:
1) negate the scalar, then splat
2) splat it, then negate the vector

```llvm
define <2 x i32> @src(i32 %x, <2 x i32> %y) {
  %not.x = xor i32 %x, -1
 %not.x.head = insertelement <2 x i32> poison, i32 %not.x, i64 0
 %not.x.splat = shufflevector <2 x i32> %not.x.head, <2 x i32> poison, <2 x i32> zeroinitializer
  %res = and <2 x i32> %not.x.splat, %y
  ret <2 x i32> %res
}

define <2 x i32> @tgt(i32 %x, <2 x i32> %y) {
 %x.head = insertelement <2 x i32> poison, i32 %x, i64 0
  %x.splat = shufflevector <2 x i32> %x.head, <2 x i32> poison, <2 x i32> zeroinitializer
  %not.x.splat = xor <2 x i32> %x.splat, shufflevector (<2 x i32> insertelement (<2 x i32> poison, i32 -1, i32 0), <2 x i32> poison, <2 x i32> zeroinitializer)
  %res = and <2 x i32> %not.x.splat, %y
  ret <2 x i32> %res
}
```

InstCombine doesn't seem to canonicalise it, but I think it could be beneficial to transform to the former.
This would aid in instruction selection for some instructions like [`vandn.vx`](https://github.com/riscv/riscv-crypto/blob/master/doc/vector/insns/vandn.adoc) on RISC-V

(Excuse the gratuitous splatting: this originally came from an example on scalable vectors, but I had to convert it to fixed for it to work on Alive)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VUGP6jYQ_jXmMgKFSQjJIQcevEiot76qd8eZEBfHRrbDsvvrKzuwC2xf1a6qSojE9sw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