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

    <tr>
        <th>Summary</th>
        <td>
            [DirectX] Add a general legalization for non-standard integer sizes.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:DirectX
      </td>
    </tr>

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

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

<pre>
    
## Background
DXIL introduced `vector reduced or` and `vector reduced and` opcodes. This maps nicely to the existing llvm intrinsics.

Our first issues shows up when icmp converts a HLSL i32 bool or bool vector to an i1. Later instcombine will bitcast these i1 vector to integers of size i2, i3, or i4 example: https://godbolt.org/z/ra3KsPrjo

These are the current known non standard ints we have observed:

1. %packed = bitcast <4 x i1> %value to i4
2. %packed = bitcast <3 x i1> %value to i3
3. %packed = bitcast <2 x i1> %value to i2

 All three are illigal for DXIL  and thus breaks the validator. Further we need to do our legalization before the scalarizer runs because it compounds the problem adding more i2s/i3s/i4s https://godbolt.org/z/Tvv5PPvc7

dxil-legalize is roughly the right time in the current pipeline to handle this legalization.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVMFu4zYQ_Rr6MoggkXYcH3Twbmq0aIAu0Bz2SpFjaTYURxhSStZfX1B2200RbC8iQOrNzJv3ZmxK1EfEVu0-Ka3PVi4cg9Ja7R43ds4DS3u73HTsv7eqPiptlDbwybqXXniOXtXHx6-_PQHFLOxnhx7Ufb2gyywgeL1hUfc12PjRm42-PPLk2GOq4HmgBKOdEkRyGL5DZsgDAr5RyhR7CGEZ13QUE7lUlarq4x-zwJkkZaCUZkyQBn5NME_wOmAEcuMEjuOCkhNY-PXpzycgo6FjDsByPW-lZQYbgZoKnmxGAYopOx47igivFAJ0lJ1NudSVEKj5AUgxY4-SgM-Q6IJAWunPQKZ8WYC2gG92nAIqc4Qh5ykpc1T6pPSpZ99xyBVLr_TpovRJrPk9fZFvfCX5vOazgmtH3CyCMcNL5NcIkSOkbKO34ksVCV4RBrsgcJdQFvQlzxqmqUDp3WTdS1HLPP7DR5nPW3gDapT5pfyy2DDjymqr6qP-Ccx8DDOqPpqfwPTHMH2tE44hQB4Er5wpBOptgDMLrJ5bHZWHOUEnaF_S2pXFBvI2s1RwmiUPKKUREdGX0J6BZ4GAvQ10sZk4QodnvrU0ORus0AUFZI4JOnR2LhJncDxOxfDXLJNwF3AE633x5FgCkE5Kn8is3236X3Gfl2X35cvi9le2_o3C3a0wBEogPPdDGYABQagfMmQaESi-U3-iCUNxZmYYbPShMKH0jmK18a3xB3OwG2yb_aGum_tam83Q6q1G3Rx25z3a88MD-tpoh7XGw67zD7bZUKtrfV8fdNM8bGttKm1ct9_t687vd66rjdrWOFoKVZnLwm6zDmCr9a65P2yC7TCk24rpigliMeIjCbr89bZspC3gu27uk9rWgVJO_4bLlMO6o_7G7B7h6D1Y6DGi2PBezeKOyPHux1koE7lOY6o2s4T2P8pQHuaucjwqfSppb8fdJPwNXS5yrjtF6dON1dLqvwIAAP__try97Q">