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

    <tr>
        <th>Summary</th>
        <td>
            [VectorCombine] foldBitOpOfCastops - failure to handle bitop(castop(x), constant_y) -> castop(bitop(x, invcast(constant_y)))
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            good first issue,
            llvm::vectorcombine
      </td>
    </tr>

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

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

<pre>
    foldBitOpOfCastops currently just folds `bitop(castop(x), castop(y)) -> castop(bitop(x, y))`

But we often have operands that have already constant folded the castop away which prevents the fold from proceeding.

The most obvious are `not` patterns:

```
  %x.cast = bitcast <4 x i32> %x to <2 x i64>
  %not = xor <2 x i64>%x.cast, splat (i64 -1)
``` 
-->
```
  %not.cast = <4 x i32> %x, splat (i32 -1)
  %not = bitcast <4 x i32> %not.cast to <2 x i64>
``` 
Any other bitcasted constants would be easy to handle as well.

But other casts that can be easily inverted (truncations, in range sext/zext etc.) could be handled as well.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVMGO4zYM_Rr5QiRwaDuJDz5kMptLDwu0Ra-FLDGxFopkSHQS9-sL2U5mp7uLAgYSUO89PlIUZYzm4ogaUb2J6j2TA3c-NL__9oe5epe1Xo_N2Vv9Zvhr__V8lJF9H0ENIZBjO8K3ITIkRASxzVvDvhe4VxNO4P4hsBZ4hFdgnAI1rETx5SP65D0SdoGIbS7yg8gPbwPDncCfmRx08kbgewrS6QjcSZ5D0gaSegTlXWTpZk-kgTta0oC8yxHunVEd9IFu5DhOxwkJ5-Cv0AeviLRxl_Wc-s-O4Oojg29vxg8RZKBUp_Mstjn0kpmCi6I4zPjkef7yA4DA6rFOyUEU79AaXv4fS3iAKTC1IGGAfYpiim5LUXx5sp2fqQ8f_gN4Kqd-xd5KBoF7sy1htUmt-84JiPywWs2iP9hznj8M_mjss3qBL_VP7n5Z2Ev9J_V98ndwI3juKDy1SL8uMsLdD1ZDS0Ayjkmrk05bAhnhTtauP6Zk1kgCy2go6RaisSMYd6OQtAXuOQxOSTbexVSlcRCkuxBEerDA0z_0YCBW6zSr6mlgTqxfmTPdFLouaplRs9lV1a6ucFtkXaNluWnbtkYqdkS40fuSCGuiGnNVl1VmGsyxyve42WyrEov15lwTFq3eV0ojqUKUOV2lsWtrb9e1D5fMxDhQs6nKXb3LrGzJxunVIl6813A2ITJMIIEo8CgQEzfNZnG4kWIflL-2xk3n1XsWmnS-aodLFGVuTeT4kY0N22kr_DUxjwuzeoefrIMVnKWxQ6DvbufXq2C52L_H_9kDxt3mEd9_osxfNgTbdMz99PjwJPB0MdwN7Vr5q8DTVPr8s-qD_0YqXevUnijwtLTx1uC_AQAA__-cvo5J">