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

    <tr>
        <th>Summary</th>
        <td>
            [HLSL] Implement `select` intrinsic
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            HLSL
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          llvm-beanz
      </td>
    </tr>
</table>

<pre>
    HLSL 2021 introduced the `select` intrinsic as a replacement for the ternary operator on vector types.

The `select` intrinsic has the following approximate forms:
```c++
template<typename T, int Sz>
void select(vector<bool, Sz> Conds, vector<T, Sz> TrueVals, vector<T, Sz> FalseVals) {
  vector<T, Sz> Result;
  for (int I = 0; I < Sz; ++I) {
 if (Conds[I])
      Result[I] = TrueVals[I];
    else
      Result[I] = FalseVals[I];
  }
  return Result;
}

template<typename T>
void select(bool Cond, T TrueVal, T FalseVal) {
  if (T)
    return TrueVal;
 return FalseVal;
}
```

The vector case can lower to a shufflevector mask:
```c++
template<typename T, int Sz>
void select(vector<bool, Sz> Conds, vector<T, Sz> TrueVals, vector<T, Sz> FalseVals) {
  vector<int, Sz> Mask;
  for (int I = 0; I < Sz; ++I) {
    Mask[I] = I;
    if (!Conds[I])
      Mask[I] += Sz;
  }
  return __builtin_shufflevector(TrueVals, FalseVals, Mask);
}
```

**Acceptance Criteria**
Implementation of the select intrinsic in the HLSL builtin headers and corresponding lowering to LLVM IR with appropriate test coverage.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVU1v4zgM_TXyhZjAluK6PviQjw02QOcyE8y1YGQm1q4sGZLcbufXLyQ7TQo0PextAwP-IPn0SL6Q6L06G6KGlWtWbjMcQ2ddo_VL_-1IaH5nR9u-NX8-_XwCnvMClAnOtqOkFkJHwB5yT5pkYA95sinjlQT0gOBo0CipJxPgZF3yD-QMujewAzkM1oE18EIyPoW3gfyC5SuWrw73oTv0CelktbavypwBh8HZf1SPIX51vWciYrCHfLok4-t45atA_aAxEBObeJrBnuDA-CbCw8_fTPzB8tWLVS3MJ_PHiRwTm6O1OromN9hY0_r4-m4_XI0HN9Iv1HftO9R-dqiBVZEZfOr4g_yoAxOTR6wh44-R6x6Y2ELOxDo9Tv5rmBLd38CqUwyZ2JbrPSu3jNcJLf5m_MmQIN-pz87z0QCkPX0Rd03pYyCrtunuKIzOfEhoMt3tyie9iC1IlY8VOly4Ti8XArclnZI_XDOeWVwCJ47zx3eAW3IXCV1VOYtVoieQaEDbV3IQLCD4bjydNM0ePfq__99CVCZcXb-ndP67EAEmiBvN7K_qmjrFeHFPqR9i-TqGp5M-E9nz83FUOijz_KEjUQo39bjJfTPB8_qL3jMer5WUNAQ0kmDjVCCncDKwfLXvB52GHQZlDdhTGlNT_27mlzLpe5qoM0_oCFtyHtC0IK1z5Adr2jjbkrziQ7Dw9PTrO-x_wKsK3TT0Bqfi0AvkA0j7Qg7PtMjaRrS1qDGjpqhyvqzrqi6yrsFW5PJY8UISLUWxPC6XbSlKibKiR0mnTDU856LgheC5eBDF4oSchEASyxIfa4lsmVOPSi_iflhYd86U9yM1VSmqKtN4JO3TJuE85sc4jzvlsk7Gs2fLXCsf_BUgqKDT9kkB5Rbey3hnAWSj000XwpDGPN8xvjur0I3HhbQ947uIPN--Dc7-lf49u8TTM75LVP8NAAD__6mYG20">