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

    <tr>
        <th>Summary</th>
        <td>
            [GISel] Add variable operand MIR patterns
        </td>
    </tr>

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

    <tr>
      <th>Assignees</th>
      <td>
            Pierre-vh
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Pierre-vh
      </td>
    </tr>
</table>

<pre>
    ## Description

Allow "parameter packs" or similar for MIR patterns to support matching any number of operands.
e.g. `G_BUILD_VECTOR` has a variable number of operands, and currently we can only write patterns for a fixed number of operands.

## Optional goals:
 - Accessing the front or back of the variadic operands list
 - Accessing the nth item of the variadic operands list
 - Additional constraints such as min/max number of arguments.
 - Rewriting the variadic operands
   - This isn't as important I think, I can't think of many patterns that'd need a variadic instruction in and out. Do it if it's trivial?

## Syntax suggestion

- `G_BUILD_VECTOR $x, $y, varargs:$others`
- `G_BUILD_VECTOR $x, $y, varargs<2,4>:$others // 2 to 4 operands`


## Potential issues

- Should the variadic operand(s) act as "one or more" or "zero or more"? e.g. in the first example above, should a 2-operand BUILD_VECTOR be allowed, or does `varargs:$others` implies at least 3 operands in total?

## Related

#87194 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVE2Pm0gQ_TXNpWQLGmzsA4fJOI4s7SrRTHavUQEF9E7TjboLx95fv2qM40nGI61yoVF_VL1671Wh96o1RIVYfRBSflHkHC2OnZBSrHYRjtxZV_zYjkpbnwshUyFT2JGvnBpYWSPinYgfLt8Hre13EFIO6LAnJgcDVi9eSAnWgVe90uigsQ7-PDzBgMzkjAe24MdhsI6hR646ZVpAcwYz9iU5sA3YgRya2i8viWjZLkGs40_fPvx1-GP37e-Pj18_P4l1DB16QDiiU1hquhNByEdAU0M1OkeG9Rm-E1RowJrw7xTTDVhAitCoE9Xvg5m_F2Y-T6Sghtai9iKdT2EBD1VF3ofSuCNonDUcSCmxeglBw-YEu1bVjwygled3IhjuQDH1__dxXasZWmWNZ4fKsAc_Vh2gh14ZIfc9nl7Via4dezJ8LRQW8ESBoSuENynnewAL-NopD8obIXMOCVQf9EXDcADulHkJQhwC89ONaSsk7YPwN2d0yELmNRii-ipsyKhCCWMVKgJlJkXtyEvYWVAMqgEV3nlgp44KtUj3d8R6PhvGE_ixbcn_aubFW4OBkNkp4BYyO4f1iA5dO8ksM8sdOS_W8W-8f5RCPmYi_fg6FAi5F3IPMjRIdiP5muFORV8sk2GFGpT3I_mfC3ru7Kjru9IJufFCbgGrSS0hpTUU_NlbR3P_Cin_JWdf7Yp0D1MvKnNxtXKegU7YD5oAS3ukUKa_5EWQizkd_ERLSYBhdFAdblsHtSUf6LvPb_CSVuQBGTShZ0hvpg9ILL-n-BNpZKp_OdnkyTaDqC7SeptuMaIiyROZpHGeJFFXpHGTbtI4oXW5zut1k22rHMt4RZuk2mQ1RaqQscziLE7jfJWskiUmeZalmzLeNlmTNaXIYupR6aXWx35pXRtN8hSbPFttI40laT_P4XBDpA-ttiVq5UnP89gV4WRRjq0XWRxa29-isWI9DfJPh2fSYrUL7X6bglfSXw_daHS66JiHC7vBaK3ibiyXle2F3E84LsticPYfqljI_ewquZ-Q_xcAAP__tQX9VQ">